Home > Back-end >  cronjob executed on wrong day
cronjob executed on wrong day

Time:10-18

I want a script to be executed each first Saturday of a quarter. Therefore I have set a crontab line up with the following

24  9    1-7   1,4,7,10   6   /absolute/path/to/script

This script was now executed yesterday, at 9:24 (ok),on Saturay (ok), but on October(ok) 16th(NOK).

Any hints what I missed or misunderstood? Thanks a lot.

CodePudding user response:

The script runs every day the first 7 days and every Saturday of the specified months.

The reason is well explained in this crontab guru page (and crontab(5)'s man page). The relevant piece is:

Note: The day of a command's execution can be specified in the following two fields --- 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), the command will be run when either field matches the current time. For example, "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

You can check that this is indeed what happens by checking the description and when your script will be run next ("next at") here.

The way to achieve what you want, i.e., run the script on the first Saturday, is described in other questions/answers. See, for instance, Run a cron job on the first Monday of every month? or How to schedule to run first Sunday of every month. In short, replace 6 with * and combine your command with a call to date.

  • Related