来自 php 的 Cron 作业(准确地说是 at 命令)

发布于 2024-09-27 04:08:27 字数 660 浏览 1 评论 0原文

我想通过使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有心的人 2024-10-04 04:08:27

您以错误的方式使用 at 命令。您需要回显命令并将其传递给at。像这样尝试一下:

$cmd = "echo wget /var/www/index.php?id=" . mysql_insert_id() . " | sudo at " . $_POST['runat'];

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'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文