chuck.amadi wrote:
Has anyone a script that will check for the last friday of the month
and if So run the monthly config backup or if not the usually daily
config.
I'm using the following. In crontab:
45 15 * * 5 root /root/monthly-date-check.py &&
/usr/sbin/amdump monthly
And then in /root/monthly-date-check.py:
#!/usr/bin/env python
# we use this with Amanda to see if it's the last friday and saturday of
the month, for
# running monthly backups
import sys
import datetime # a thing of beauty and a joy forever
FIRST = 0
SECOND = 1
THIRD = 2
FOURTH = FORTH = 3 # for people who have finger trouble
FIFTH = 4
LAST = -1
SECONDLAST = -2
THIRDLAST = -3
MONDAY = MON = 0
TUESDAY = TUE = TUES = 1
WEDNESDAY = WED = 2
THURSDAY = THU = THUR = 3
FRIDAY = FRI = 4
SATURDAY = SAT = 5
SUNDAY = SUN = 6
JANUARY = JAN = 1
FEBRUARY = FEB = 2
MARCH = MAR = 3
APRIL = APR = 4
MAY = 5
JUNE = JUN = 6
JULY = JUL = 7
AUGUST = AUG = 8
SEPTEMBER = SEP = 9
OCTOBER = OCT = 10
NOVEMBER = NOV = 11
DECEMBER = DEC = 12
def
dow_date_finder(which_weekday_in_month=FIRST,day=MONDAY,month=JANUARY,year=2000):
dt = datetime.date(year,month,1)
dow_lst = []
while dt.weekday() != day:
dt = dt + datetime.timedelta(days=1)
while dt.month == month:
dow_lst.append(dt)
dt = dt + datetime.timedelta(days=7)
return dow_lst[which_weekday_in_month] # may raise an exception
if slicing is wrong
if __name__ == "__main__":
now = datetime.date.today()
fri = dow_date_finder(LAST, FRIDAY, now.month, now.year)
sat = datetime.date.fromordinal(fri.toordinal() + 1)
if now == fri or now == sat:
sys.exit(0)
else:
sys.exit(1)
--
Graeme Humphries (graeme.humphries AT vcom DOT com)
(306) 955-7075 ext. 485
My views are not the views of my employers.
|