• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

BASH> Check for last day of the month

Apr01
2011
Written by Scott Rowley

Script is meant to be used with other scripts in order to determine if it is the last day of the month. Useful for making sure a particular script runs at the end of the month. Just add a cron job that checks this every day at the time you would want your code run if it was indeed the last day of the month.

2 0 * * * /usr/bin/last-day-of-the-month.sh
#!/usr/bin/bash
# last-day-of-the-month.sh
# By: Scott Rowley
# http://www.sudobash.net/
#########################################
TODAY=`/usr/local/bin/date +%d`
TOMORROW=`/usr/local/bin/date +%d -d "1 day"`
# See if tomorrow's day is less than today's
if [ $TOMORROW -lt $TODAY ]
then
echo "Today is the last day of the month, running code…"
/run/your/code
fi
exit 1
Posted in BASH
« BASH> sudo bash
» Ubuntu 10.10 VNC Login Screen

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top