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

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

问题描述

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

I want to be able to programatically add a new cron job, what is the best way to do this?

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

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 -

有更好的方法吗?

推荐答案

如果您以 root 身份运行,最好的方法是将文件放入/etc/cron.d

The best way if you're running as root, is to drop a file into /etc/cron.d

如果你使用包管理器来打包你的软件,你可以简单地将文件放在那个目录中,它们被解释为好像它们是 crontabs,但有一个额外的用户名字段,例如:

if you use a package manager to package your software, you can simply lay down files in that directory and they are interpreted as if they were crontabs, but with an extra field for the username, e.g.:

文件名:/etc/cron.d/per_minute

内容:* * * * * root/bin/sh/home/root/script.sh

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

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