Results 1 to 6 of 6
Hi,
I created cron job to run every two weeks on Monday however it's not working for some reason (the command itself works fine - it's just not executed by ...
- 05-30-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 14
Cron Job every two weeks
Hi,
I created cron job to run every two weeks on Monday however it's not working for some reason (the command itself works fine - it's just not executed by cron). Could you please check if the syntax is correct:
05 01 * * 1/2 root /bash_script.sh
Regards
- 05-31-2011 #2
How about this;
5 1 * * 1/2 root /bash_script.sh
You don't need the leading '0'. It should work.
How/where did you place this command?
- 05-31-2011 #3Just Joined!
- Join Date
- Feb 2011
- Posts
- 14
Hi
I can try without this leading 0 however I have another command which is running fine:
00 01 * * * root /bash_script.sh
I just created crontab in /etc/cron.d/ directory
- 05-31-2011 #4Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Leading zeroes is irrelevant so specifying 05 or 5 is the same. The crontab entry:
05 01 * * 1/2 root /bash_script.sh
The 5th field specifies day-of-week so 1/2 says to run the script on Monday, Wednesday, Friday, and Sunday (1,3,5,7).
Cron doesnt have a way to specify every other week. Best you can do is have your script run every week and put code in your script to determine whether the week of the year is odd or even. So to run the script on an even week of the year:
To have your script run every Monday:Code:#!/bin/sh WK=`date +%W` ON_WK=`expr $WK % 2` if [ $ON_WK = 1 ]; then echo "NOT even week" exit 1 fi
05 01 * * 1 root /bash_script.sh
- 06-01-2011 #5Just Joined!
- Join Date
- Feb 2011
- Posts
- 14
Thanks for help.
- could you confirm what fields (like m, h, d) accept '/' switch
- 06-01-2011 #6Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Refer to the crontab file man page:
Code:# man 5 crontab


Reply With Quote