You can use this post as a reference to schedule the Cronjobs in more Granular fashion.
Situation:
Situation:
We had a requirement to execute couple of scripts on specific Saturdays of a month throughout the year i.e., First script (say /opt/firstscript.sh) should be executed on all Saturdays EXCEPT first Saturday of the month, and the Second script (say /opt/secondscript.sh) should be executed ONLY on first Saturday of the month. This we required to do for scheduling Weekly Tape backups.
Executing a script on all Saturdays is fairly simple, we need to just specify number 6 on 5th column on crontab entry, but here the scenario is different.
The solution for this is shown below. This uses ‘date’ command to check if the current date is a first Saturday of a month.
0 2 * * 6 [ $(date +%d) -gt 7 ] && /opt/firstscript.sh
# Executes at 2am on all Saturdays Except the first Saturday of the month (Saturdays other than 1st can fall only after 7th ).
# Executes at 2am on all Saturdays Except the first Saturday of the month (Saturdays other than 1st can fall only after 7th ).
0 22 * * 6 [ $(date +%d) -le 7 ] && /opt/secondscript.sh
# Executed at 10 PM ONLY on first Saturday of the month (A first Saturday can either be 7th or less than that ).