【发布时间】:2013-07-17 10:22:49
【问题描述】:
我正在使用 php 脚本创建动态 cronjob。 cron 作业添加功能对我来说工作正常。我的脚本如下。
<?
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
?>
我需要使用 php 编辑单独的 cronjob。我正在尝试很多方法,但它不起作用。下面给出了我的编辑 cron 脚本
-e (编辑用户的 crontab)
<?
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('-e crontab /tmp/crontab.txt');
?>
我的参考链接LINK
如何使用 php 编辑 cron 作业。请指教
【问题讨论】:
-
php 是否具有写入 crontab 文件的正确权限?
-
@jam6549 如何设置此权限以及如何访问。请指导我
-
如果您使用的是linux,请将文件的所有者更改为
www-data:sudo chown www-data /tmp/crontab.txt -
你为什么要做
echo exec('-e crontab /tmp/crontab.txt');? -
查看我的参考链接@ansh0l
标签: php cron crontab cron-task