I think that will run the backup every other week, not the 2nd and 4th week of a month... Since there is no way of telling what week you are in in the current month, we use to create a date file and then check the date against it..
So you can set up the backup to run in crontab every Friday.
In the script check the date:
DATE=`date +%m%d%y`
if [`grep -qx $DATE RUNDATE.lst` -eq 0 ]
then
run backup
else
don't run backup
fi
This is sloppy and you will have to manually set it up for a few years.... But it will work....
The following command will give you the two dates you are after. (ie. 2nd and 4th Friday of the current month).
cal | tail +3 | cut -c21-22 | grep "[0-9]" | sed -n '2p;4p'
You can change the day from friday to another by tweaking the cut command, or change the week in the month by tweaking the sed command.
Setup a script to exec via cron every friday, with something like the following verify function to prevent actually executing on the wrong days.
Today=`date +%e`
RunDays=`cal | tail +3 | cut -c21-22 | grep "[0-9]" | sed -n '2p;4p'`
if [[ `echo "$RunDays" | grep $Today` -ne $Today ]]
then # Exit Cleanly
exit 0
fi
# Now running rest of script seeing as its either 1st or 4th Friday of this month.
Hope the above is of some use to you
Best Regards to all.
____________________
Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debuging Mondays code.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.