Linux 将 10 分钟的 cron 作业添加到 Ubuntu 包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10289970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add 10 minute cron job to Ubuntu package
提问by Jeroen
I need to install some cron jobs with my Ubuntu installation package. The ones that run every day or hour are easy: I can just create a symlink from /etc/cron.daily
to my script.
我需要用我的 Ubuntu 安装包安装一些 cron 作业。每天或每小时运行的程序很简单:我只需创建一个/etc/cron.daily
指向我的脚本的符号链接即可。
However, I also have a script that I would like to run every 10 minutes. There is no such thing as /etc/cron.minutely
. Also I am not sure how to edit crontab without using the interactive editor (crontab -e
). What is the best way to go about this?
但是,我还有一个脚本,我想每 10 分钟运行一次。没有这样的事情/etc/cron.minutely
。此外,我不确定如何在不使用交互式编辑器 ( crontab -e
) 的情况下编辑 crontab 。解决这个问题的最佳方法是什么?
采纳答案by laher
Your package can simply put a file in /etc/cron.d/
您的包可以简单地放入一个文件 /etc/cron.d/
The text file should contain something like this, to run a command every 10 minutes:
文本文件应包含如下内容,每 10 分钟运行一次命令:
*/10 * * * * root /path/to/command
Google 'cron format' for more info, and yes, this belongs in askubuntu or superuser.
谷歌“cron 格式”了解更多信息,是的,这属于 askubuntu 或超级用户。
You need to add the username (root) to the line, as shown above. Apparently this is necessary for files in cron.d, but I can't find a definitive document.**
您需要在行中添加用户名 (root),如上所示。显然,这对于 cron.d 中的文件是必需的,但我找不到明确的文件。**
cron should pick this new job up automatically.
cron 应该自动选择这个新工作。