简体   繁体   中英

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.

I have not set a cron job up before, I was planning to put the following in cron.daily :

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

Is this correct?

cron.daily does not run your scripts for every 30 minutes. You can create a new crontab entry for your requirement by doing

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.

There are custom-strings you can use for scheduling actions and it does not apply at the 30-minute level.

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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