Question

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?

Was it helpful?

Solution

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'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top