简体   繁体   中英

How to write a cron for every 30 minutes between 2AM to 4AM?

I was trying to figure a cron for every 30 minutes between 2AM to 4AM? So the cron run time will be: 2:00 2:30 3:00 3:30 4:00

Every hour will be something like this: 0 2,3,4 * * * command

Thank You.

I'd just write it as two distinct rules:

0,30 2-3 * * * /run/this/command
0    4   * * * /run/this/command

If you're the sort that worries about this sort of thing (I'm not), you can use a conditional to get it onto one line:

0,30 2-4 * * * [[ "$(date +%H%M)" != "0430" ]] && /run/this/command

This will run the command given at 4:30 as well, but not actually call your script unless the time is something other than 4:30.

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