Run a cron job on the first Monday of every month?
You can put the condition into the actual crontab command (generic way):
[ "$(date '+%u')" = "1" ] && echo "It's Monday"
if your locale is EN/US, you can also compare strings (initial answer):
[ "$(date '+%a')" = "Mon" ] && echo "It's Monday"
Now, if this condition is true on one of the first seven days in a month, you have its first Monday. Note that in the crontab, the percent-syntax needs to be escaped though (generic way):
0 12 1-7 * * [ "$(date '+\%u')" = "1" ] && echo "It's Monday"
if your locale is EN/US, you can also compare strings (initial answer):
0 12 1-7 * * [ "$(date '+\%a')" = "Mon" ] && echo "It's Monday"
Replace the echo
command with the actual command you want to run. I found a similar approach too.
I have a computer with locale on Spanish, so, this approach isn't working for me because mon changes to lun
Other languages would fail as well, so, I did a slight variation on the accepted answer that takes out the language barrier:
0 9 1-7 * * [ "$(date '+\%u')" = "1" ] && echo "¡Es lunes!"