Home > Software design >  Crontab skip run once a week
Crontab skip run once a week

Time:11-15

I have a CRON expression that will run a given command every 8 hours, beginning at 00:00.

0 0,8,16 * * * 

This will run a given commend 21 times a week, however, my goal is to skip one of these 21 runs on a weekly basis. What is the proper CRON expression to skip the first run on Sunday each week at 00:00 (in other words, an expression that will run 20 times per week)?

CodePudding user response:

Make it 2 lines:

0 0,8,16 * * 0-5 At minute 0 past hour 0, 8, and 16 on every day-of-week from Sunday through Friday.

And

0 8,16 * * 6 At minute 0 past hour 8 and 16 on Saturday.

You can change the day and hour which you want to skip, but there is no way to do this in 1 line as far as I know.

CodePudding user response:

Place this: [[ ( $( date \%u ) -ne 0 ) && ( $( date \%H:\%M) != "00:00" ) ]] && before your command.

If you don't want to use bash for your cron-job, this works with sh:

[  $( date  \%u ) -ne 0  ] && [ $( date  \%H:\%M) != "00:00"  ] &&
  • Related