In this post we will learn,Run cron job alternate week day.
Today, I met with very good question i.e how to run cron job alternate week day. The user wants to run the script in alternate Saturday.When I read this question first time,it make me to take a pause for a while. Later thinking on some more logic,I ended up with nice way to accomplish this task .
What is cron
Cron is a software utility,basically a job scheduler in Linux and Unix like operating system.
Cron information are saved in crontab which is also know as cron table.The format of writing crontab is given below
Minute Hour date-Of-Month Month Day-Of-Week /path/of/command-script
Task : We got a task to run cron job alternate week day. For eg. run a cronjob in alternate Monday,Tuesday,thursday etc.
See given below examples
Time to run script : 12.30 AM
Month : Run the script every month
Day of Week : Alternate day of week
Day of week represented in Crontab as follows
Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Firday = 5
Saturday = 6
On alternate Monday
30 00 1-2,15-16,29-31 * 1 give-path-of-script-command
On alternate Tuesday
30 00 1-3,15-17,29-31 * 2 give-path-of-script-command
On alternate Wednesday
30 00 1-4,15-18,29-31 * 3 give-path-of-script-command
On alternate Thursday
30 00 1-5,15-19,29-31 * 4 give-path-of-script-command
On alternate Friday
30 00 1-6,15-20,29-31 * 5 give-path-of-script-command
On alternate Saturday
30 00 1-7,15-20,29-31 * 6 give-path-of-script-command
On alternate Sunday
30 00 1-7,15-20,29-31 * 0 give-path-of-script-command