How to write shell scripts that execute batch jobs with crontab only at month-end
I’ll introduce how to write shell scripts that execute batch jobs with crontab only at month-end.
if /usr/bin/test $( date -d '+1 day' +\\%d ) -eq 1
then
echo "1st day of the month"
fi
Here’s sample crontab code that executes the shell script /path/to/script.sh at 3 AM on the last day of the month:
0 3 28-31 * * /usr/bin/test $(date -d '+1 day' +\\%d) -eq 1 && /path/to/script.sh >> /path/to/your.log 2>&1
Since month-end dates are only between 28-31, cron executes on these dates.
That’s all from the Gemba that wants to execute processing at month-end with cron.