Reputation: 474
We want to schedule a job that runs on a weekday on the 12th or on the first weekday after the 12th. Can I specify that in cron?
Upvotes: 1
Views: 589
Reputation: 7225
You can't define such logic in cron
and the usual way is to add it in to the script you want to run. So run the script every day like this:
0 0 * * * /path/to/script.sh
and add inside
if [ "$(date +%d%m)" == "0101" ]
then rm -f /var/run/flag
fi
if [ $(date +%d) -ge 12 ] && [ $(date +%w) -gt 0 ] && [ $(date +%w) -lt 6 ] && [ ! -f /var/run/flag ]
then <do the work>
touch /var/run/flag
fi
exit
Also you should take care to run only once (as far as I understand)
Upvotes: 2