I want to run a script every Saturday except for the first Saturday of each month. (The script monitors a maintenance window, and the window is longer on the first Saturday of the month.)
Here is what I have:
*/15 17-18 8-31 * * [ "$(date '+\%a')" = "Sat" ] && <Then run my script>
Here is what I'm looking at:
*/15 17-18 * * 6 [ "$(date '+\%d')" > "7" ] && <Then run my script>
I feel like the first example creates too many unnecessary attempts as it runs every day after the first seven days of the month but only will process the monitoring script on Saturdays.
In the second example, I'm attempting to run the script only on Saturdays but only if the day of the month is greater than 7. I'm not sure how to do it using the 'day of the month' result from the date command, and I'm not sure if this will work. Specifically, should I use the '>' symbol or a 'gt' bash-like function?
Is there a better way to achieve this other than what I have here?
Thanks for your input. I've looked at other examples similar to this but most of them only addressed running a script on the first weekend of the month.
Try this:
*/15 17-18 * * 6 [ $(date '+\%d') -gt 7 ] && <Then run your script>
From help test:
-gt: greater-than