将10分钟的cron作业添加到Ubuntu包中

时间:2023-01-18 07:59:13

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。最好的方法是什么?

1 个解决方案

#1


14  

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.

Google的“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应该自动选择这个新工作。

#1


14  

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.

Google的“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应该自动选择这个新工作。