cron job that runs on the last monday of the month
Solution 1:
That is setup to go multiple times per day. You want:
0 8 04 19-26 * * MON $HOME/bin/mailstub
That will go off at 8:04:00 on any day between the 19-26 that is on a Monday of any month of any year.
However, if it is Monday on the 19th, it is monday on the 26th. Therefore, you would want to have it from the 19-25
0 8 04 19-25 * * MON $HOME/bin/mailstub
So, this should go off once per month on a Monday. However, it is not guarenteed (or likely) to be the last Monday. If you need it to be the last and the L syntax does not work, you need to program the logic into the script being called. This is easily done with python but is beyond the scope of this question.
Solution 2:
Your cron job wil run on a Tuesday (5th field, day of week, 0 or 7 is Sunday), and not always the last Tuesday of the month. It would be better to use:
8 04 * * 1 [ $(date +"\%m") -ne $(date -d 7days +"\%m") ] && $HOME/bin/mailstub
This checks if the month today is not equal to the month 7 days from now. If not equal then it's the last monday of the month.
Solution 3:
You can use the following:
For monday :
30 10 25-31 1,3,5,7,8,10 * test $(date +\%w) -eq 1 && cmd
every Monday between the 25th and the 31st the months in 31 days at 10:30 am
30 10 24-30 4,6,9,11 * test $(date +\%w) -eq 1 && cmd
every Monday between the 24th and the 30th month in 30 days at 10:30 am
30 10 22-29 2 * test $(date +\%w) -eq 1 && cmd
every Monday between the 22nd and 29th of February at 10:30 am
For Wednesday:
30 10 25-31 1,3,5,7,8,10 * test $(date +\%w) -eq 3 && cmd
every Wednesday between the 25th and the 31st the months in 31 days at 10:30 am
30 10 24-30 4,6,9,11 * test $(date +\%w) -eq 3 && cmd
every Wednesday between the 24th and the 30th month in 30 days at 10:30 am
30 10 22-29 2 * test $(date +\%w) -eq 3 && cmd
every Wednesday between the 22nd and 29th of February at 10:30 am