Cron job; Last day of the month?

ersinacar

New member
Joined
Jun 4, 2008
Messages
3
Hi there!
I need to run a file at the last day of the month. but i cant figure it out.

Minute 0-59
Hour 0-23
Day of Month 1-31
Month 1-12
Day of Week 0-7 (0 or 7 = Sunday)

if i enter 31 to "Day of Month" it will run only at 31 (right ?).
i need to run at "last day of the month 23:40:00"

how can do this ?

Thanks for your help :)
 
In that case, try

Have cron run a script on days 28, 29, 30 and 31 of every month.
Create two variables in the script, one containing today's day of the
month and another containing tomorrow's day of the month:

TODAY=`date +%d`
TOMORROW=`date +%d -d "1 day"`
# See if tomorrow's day is less than today's
if [ $TOMORROW -lt $TODAY ]; then
echo "This is the last day of the month"
# Do php/etc stuff ...
fi


or..... set the cron to just 23:40 then :
Code:
[ `date +%d` -eq `echo \`cal\` | awk '{print $NF}'` ] && <script name goes here>
(not sure if this will work tho due to permissions?)

Or........ you can do it in PHP

Code:
$thismonth=date("F");
    $checkmonth=date("F", strtotime("tomorrow"));

    if ($checkmonth!=$thismonth) {
      // include the file you want to run
     include "/full/path/to/script";
    }
    ?>

set cron like this:
40 23 * * * /path/to/php/php -q /path/to/file.php

I dunno........
 
Last edited:
One thing I thought of: maybe just run it at 0:00 on the 1st day of the month? If it doesn't really needs to be the exact last day that is.
 
Back
Top