1833873 Members
4205 Online
110063 Solutions
New Discussion

Crontab end of month

 
SOLVED
Go to solution
John Demeny
Advisor

Crontab end of month

I want to set a job to run on the last day of each month. Accordingly, I have crontab lines for
31st day of months 1,3,5,7,8,10,12
30th day of months 4,6,9,11
28th, 29th day of month 2

I put in 28th and 29th to catch leap years. If the current year does not have a Feb 29th, will crontab blow up, or just not run twice that month?
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Crontab end of month

No, cron will handle that just fine. However, you could do this with one entry on the 28-31 of EVERY month and then let the script itself determine if this is the last day of the month.

#!/usr/bin/sh

if [[ $(caljd.sh -M) -ne $(caljd.sh -n 1 -M) ]]
then
echo "Last Day of Month; do your thing"
fi

Here's caljd.sh. Invoke as caljd.sh -u for full usage and to find out what it does.


If it ain't broke, I can fix that.