如何以编程方式创建新的cron作业? [英] How can I programmatically create a new cron job?
问题描述
我想要能够以编程方式添加新的cron作业,最好的方法是什么?
从我的研究,似乎我可以转储当前的crontab,然后附加一个新的,管道系统回到crontab:
(crontab -l; echo0 * * * * wget -O - -q http://www.example.com/cron.php) |有没有更好的方法?
$ b <
你应该考虑一个稍微更复杂的脚本,它可以做三件事情。
p>-
附加crontab线;确保它不存在。
-
删除crontab行。
-
以上两个功能的组合取代了crontab行。
I want to be able to programatically add a new cron job, what is the best way to do this?
From my research, it seems I could dump the current crontab and then append a new one, piping that back into crontab:
(crontab -l ; echo "0 * * * * wget -O - -q http://www.example.com/cron.php") | crontab -
Is there a better way?
It's always worked well for me.
You should consider a slightly more sophisticated script that can do three things.
Append a crontab line; assuring that it didn't exist. Adding when it already exists is bad.
Remove the crontab line. Perhaps only warning if it didn't exist.
A combination of the above two features to replace the crontab line.
这篇关于如何以编程方式创建新的cron作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!