ring bearer ring bearer - 2 years ago 197
Bash Question

cron : how to schedule to run first Sunday of every month

Hi I need to schedule a cron job to run at at 9:00 AM on first Sunday of every month.
Did a little research and see that there is no short hand in cron to this.
Do you know of an optimal way ?
Using Bash+RHL

Answer Source

You can put something like that in crontab file:

00 09 * * 7 [ $(date +\%d) -le 07 ] && /run/your/script

The date +%d gives you number of current day and than you can check if the day is lesser or equal of 7. If it is that run your command.

If you run these script only in Sundays it should means that it runs only in the first Sunday of the month.

Remember, that in the crontab file the formatting options for date command should be escaped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download