tags:

views:

20

answers:

1

Hi,

I want to run a script just ONCE by setting up a cron job using "at" command. I'm using this now:

<?php
include "config.php";
if (isset($_POST['add']))
{
 $sql = mysql_query("INSERT INTO {$table}(msg) VALUES('{$_POST['msg']}')");
 if ($sql)
 {
  $cmd = "wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];
  exec($cmd);
  echo exec("atq");
  echo $cmd;
 }
 exit();
}

echo "<form action='{$_SERVER['PHP_SELF']}'  method='POST'>";
echo "<input type='text' name='msg' />";
echo "<input type='text' name='runat' />";
echo "<input type='submit' name='add' />";
echo "</form>";

?>

However, this doesn't seem to be working. Am I doing this right? Or could you recommend something else?

+1  A: 

You are using at command in wrong way. You need to echo command and pass it to at. Try it like that:

$cmd = "echo wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];
Māris Kiseļovs
Sorry, but that doesn't work :( There's no jobs in queue when I run "atq" or "sudo atq". Maybe this has something to do with permissions?
bah
@bah: at first you should try to execute same command in shell. Maybe there is no `at` available on that system, maybe atd daemon is not running, maybe...
Māris Kiseļovs
Thank you for helping, but I already solved my problem. I just had to add "www-data" user to at.allow file. :)
bah