It's not that difficult to find other method to calc the last day, mine was just idea.
Take a look at cal
or
Solution 1 (using date, change MET to your local time zone)
#!/bin/sh
if test `TZ=MET-24 date +%d` = 1; then
# today is the last day of month
fi
You can call this script from cron, say with a crontab of
4 2 28-31 * * /path/to/your/script
Solution 2 (more generic, using perl5)
#!/usr/bin/perl -w
#
# last-day-of-month - check if today is the last day of a month
#
# Input: none.
# Output: none.
# Exit status: 0 (true) if today is the last day in a month, otherwise 1.
# Algorithm: Get localtime and advance the day of month by one. Let mktime
# normalize the result and check whether day of month became 1.
# Requires: perl5.
#
use POSIX;
@the_time = localtime (time);
++$the_time[3]; # Element 4 is the day of month [1..31]
if ((localtime (POSIX::mktime (@the_time)))[3] == 1) {
exit 0;
}
exit 1;
or
perl: $logDate = time() - (3600 * 24);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime($logDate);
--
| Mike Nixon
| Unix Admin
|
----------------------------