Date manipulation to check for last day of the month.
On last day of the month, few special scripts are set to run. Lot of years ago custom scripts were created to check for last day of the month (leap years etc) or cal
was used to display calendar and extract the last day out. New datestring
allow for simple date manipulation to get the same info in one line.
# Check if tomorrow is the first day of next month.
if [[ "$(date -d tomorrow +'%d')" = 01 ]]
then
echo "Today is last day of the month"
fi
# Just for testing if running this in middle of the month :)
if [[ `date +%d -d "+16 days"` = 01 ]]
then
echo "Last day of the month is 15 days away"
fi
Play with other options like date -d "+1 month"
, default to first day and subtract 1 day and check if matches.