[英]Can I modify the schedule of a cron job from a php script that it is being executed by another cron job?
For example I have a cron running on the 1st of every month, this cron executes a PHP script that returns some dates.例如,我在每个月的 1 号运行一个 cron,这个 cron 执行一个返回一些日期的 PHP 脚本。
I want to use these dates and modify the schedule of another cron job?我想使用这些日期并修改另一个 cron 作业的时间表?
I know I can add a new cronjob doing something like this but unsure of how to update 1 specific entry when there could be multiple.我知道我可以添加一个新的 cronjob 做这样的事情,但不确定如何在可能有多个时更新 1 个特定条目。
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
Make sure you do not break something you better monitor your cronjobs after you deploy this 😉 But what you want to do is possible.确保你在部署这个之后不要破坏你更好地监控你的 cronjobs 的东西😉但是你想做的事情是可能的。
You can create, modify and delete Cronjobs via PHP ( Use PHP to create, edit and delete crontab jobs? )您可以通过 PHP 创建、修改和删除 Cronjobs( 使用 PHP 来创建、编辑和删除 crontab 作业? )
This is also true if this PHP is executed via another cronjob (as long as you give the correct permissions)如果这个 PHP 是通过另一个 cronjob 执行的,也是如此(只要你给了正确的权限)
⇒ It is possible (qed) ⇒ 有可能 (qed)
Also see this question: https://askubuntu.com/questions/408611/how-to-remove-or-delete-single-cron-job-using-linux-command另请参阅此问题: https : //askubuntu.com/questions/408611/how-to-remove-or-delete-single-cron-job-using-linux-command
This is how you remove a single cronjob (by example) - just create a new one for the different dates:这是您删除单个 cronjob 的方式(例如)-只需为不同的日期创建一个新的:
crontab -u mobman -l | grep -v 'perl /home/mobman/test.pl' | crontab -u mobman -
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.