[Gllug] crontab 'last friday in each month'

Mike Brodbelt mike at coruscant.demon.co.uk
Mon Dec 8 19:16:17 UTC 2003


On Mon, 2003-12-08 at 12:05, Tethys wrote:
> Richard Jones writes:
> 
> >This runs the script on the first Monday of the month (assuming I've
> >got this correct ...):
> >
> >0 15 1-7 * 1 script.sh
> >
> >How can I run the script on the last Friday of each month?
> 
> Run it on every Friday, and have the script itself bail if there are
> less than 7 days to the end of the month. Can't think of an easy way
> of doing it directly with cron, though.

I use a script to do this - it runs Amanda for backups, but uses a
different config on the last Friday in the month:-

# ================================================= #

# Day of week to switch to alternate configuration. On the last
# KEEPDAY of each month, Amanda will be started with the
# alternate configuration. The value must be the day name
# as output by "date +%A"

KEEPDAY=Friday

# Name of standard configuration

AM_CONFIG=acu

# Name of alternate configuration

AM_ALT_CONFIG=acukeep

# ================================================= #

if echo `date +%A` | grep $KEEPDAY > /dev/null
then
        if echo `date --date '1 week' +%B` | grep `date +%B` > /dev/null
        then
                CONFIG=$AM_CONFIG
        else
                CONFIG=$AM_ALT_CONFIG
        fi
else
        CONFIG=$AM_CONFIG

fi


That's the important bit - you should be able to easily cobble that into
a script to run whatever you want. It does depend on GNU date, so there
may be issues if you're running it on a platform where the default date
command is not the GNU one.

HTH,

Mike.


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list