We have a detailed instruction of using crontab on Linux system. This tutorial will help you to configure cron job to run on every last day of the Month. As there is no direct option available to do it.
So, first of all, we will schedule cron on 28,28,29 and 31’st of each month. Now find if today is the last day of the month. To find it check if the next day is 01’st of next day and then only execute any command.
Below command will return the date of the next day.
date +%d -d tomorrow
Now check if tomorrow is 01.
[ "$(date +%d -d tomorrow)" = "01" ] && echo "True"
If the next day is 01 then above command will print “True” on screen. Here you can use the above script in crontab and change echo with your command.
59 23 28-31 * * [ "$(date +%d -d tomorrow)" = "01" ] && /root/script.sh