来自 php 的 Cron 作业(准确地说是 at 命令)
我想通过使用“at”命令设置 cron 作业来运行脚本一次。 我现在正在使用这个:
<?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>";
?>
但是,这似乎不起作用。我这样做对吗?或者你能推荐别的东西吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以错误的方式使用
at
命令。您需要回显命令并将其传递给at
。像这样尝试一下:You are using
at
command in wrong way. You need to echo command and pass it toat
. Try it like that: