View Single Post
Old 29-Nov-2007, 02:57 AM   #2 (permalink)
Anilrgowda
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default Re: How to run a cron job every two weeks for a script and if it can be done how do y

I've never heard of any unix cron that doesn't accept the standard cron format which I posted above. Here are some more examples:

01 * * * * hourlycmd runs every hour at :01
02 4 * * * dailycmd runs at 4:02 am everyday
22 4 * * 0 weeklycmd runs each week on sunday (0 day) at 4:22 am
42 4 1 * * monthlycmd runs the first day of each month at 4:42am

As far as I know you can't make cron do something every other two weeks. But in the script you call with cron you can add a test to see if you ran last week or not, so effectively it will only run every two weeks.

Use this:
if test -f /somedir/ranlastweek
then
rm /somedir/ranlastweek
exit
fi
touch /somedir/ranlastweek #touch creates the file or if it already exists updates its timestamps
The commands you want to run every two weeks here

(props to omarfarid for this simple script)


------------------


Anilrgowda is offline   Reply With Quote