What’s the cron (linux) syntax to have a job run on the 2nd and 4th Saturday of the month?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The second Saturday of the month falls on one (and only one) of the dates from the 8th to the 14th inclusive. Likewise, the fourth Saturday falls on one date between the 22nd and the 28th inclusive.
You may think that you could use the day of week field to limit it to Saturdays (the
6in the line below):Unfortunately, the day-of-month and day-of-week is an OR proposition where either will cause the job to run, as per the manpage:
Hence you need to set up your
cronjob to run on every one of those days and immediately exit if it’s not Saturday.The
cronentry is thus:(to run at 1am on each possible day).
Then, at the top of
/path/to/myscript, put:And, if you can’t modify the script (e.g., if it’s a program), simply write a script containing only that check and a call to that program, and run that from
croninstead.You can also put the test for Saturday into the
crontabfile itself to keep the scheduling data all in one place: