Pergunta

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?

Foi útil?

Solução

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'];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top