简体   繁体   English

让cron作业每30分钟运行一次-使用cron.hourly?

[英]Getting a cron job to run every 30 minutes - using cron.hourly?

I would like to set up a cron to run a shell script every half an hour on my Linux server. 我想设置一个cronLinux服务器上每半小时运行一次shell脚本。

I have not set a cron job up before, I was planning to put the following in cron.daily : 我之前没有设置过cron工作,我打算将以下内容放入cron.daily

*/30 * * * * /path/to/my/script 

Is this correct? 这个对吗?

cron.daily does not run your scripts for every 30 minutes. cron.daily不会每30分钟运行一次脚本。 You can create a new crontab entry for your requirement by doing 您可以通过执行以下操作来创建新的crontab条目:

crontab -e

and then adding a line 然后添加一行

0,30 * * * * /path/to/script

(or) (要么)

0/30 * * * * /path/to/script

for your requirement. 根据您的要求。 You can confirm if your entry has been added to the list by doing crontab -l which lists all the scheduled crontab actions. 您可以通过执行crontab -l列出所有计划的crontab操作来确认您的条目是否已添加到列表中。

There are custom-strings you can use for scheduling actions and it does not apply at the 30-minute level. 您可以使用一些自定义字符串来安排操作,但不适用于30分钟级别。

@reboot  #Runs at boot
@yearly  #Runs once a year [0 0 1 1 *]
@annually  #Runs once a year [0 0 1 1 *]
@monthly  #Runs once a month [0 0 1 * *]
@weekly  #Runs once a week [0 0 * * 0]
@daily  #Runs once a day [0 0 * * *]
@midnight  #Runs once a day [0 0 * * *]
@hourly  #Runs once an hour [0 * * * *]

Using the above, something like below can be done. 使用上面的方法,可以完成下面的操作。

@hourly /my-path/to/another-script

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM