简体   繁体   English

动态添加cron作业

[英]Adding cron job dynamically

I want to add a cron job dynamically by storing the command in a text file and then using the exec command in my PHP code to run it. 我想通过将命令存储在文本文件中,然后在我的PHP代码中使用exec命令来运行它来动态添加cron作业。

My text file named cron.txt contains 我的文本文件cron.txt包含

*/5 * * * * /usr/local/bin/php -f public_html/bookmark/email.php

My relevant PHP code is 我相关的PHP代码是

exec('crontab cron.txt', $a, $return);

When I run the code it the $return is set to error code 1 and no cron job is added. 当我运行代码时, $ return设置为错误代码1,并且不添加任何cron作业。 I have done this before without issues but I am missing something today! 我以前做过这个,没有问题,但是今天我丢失了一些东西!

确保Apache用户(例如“ www-data”)或以CLI身份运行脚本的用户具有cron.txt文件的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM