문제

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?

도움이 되었습니까?

해결책

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'];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top