如何以编程方式创建新的cron作业? [英] How can I programmatically create a new cron job?

查看:142
本文介绍了如何以编程方式创建新的cron作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要能够以编程方式添加新的cron作业,最好的方法是什么?



我的研究,似乎我可以转储当前的crontab,然后附加一个新的,管道系统回到crontab:

 (crontab -l; echo0 * * * * wget -O  -  -q http://www.example.com/cron.php) |有没有更好的方法?


$ b <



你应该考虑一个稍微更复杂的脚本,它可以做三件事情。

p>


  1. 附加crontab线;确保它不存在。


  2. 删除crontab行。


  3. 以上两个功能的组合取代了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.

  1. Append a crontab line; assuring that it didn't exist. Adding when it already exists is bad.

  2. Remove the crontab line. Perhaps only warning if it didn't exist.

  3. A combination of the above two features to replace the crontab line.

这篇关于如何以编程方式创建新的cron作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆