cron to get executed on 2nd and 4th saturday of every month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cron to get executed on 2nd and 4th saturday of every month
# 1  
Old 08-14-2012
cron to get executed on 2nd and 4th saturday of every month

Hi ,
i need to reboot a server during 2nd and 4th saturday every month. i have come up with the below cron

Code:
 
30 17 8-14 * * if [ `date +\%u` -eq 6 ] ; then /rebootscript; fi # to reboot every second saturday
30 17 22-28 * * if [ `date +\%u` -eq 6 ] ; then /rebootscript; fi # to reboot every fourth saturday

I am wondering why it does not work this way

Code:
 
30 17 8-14 * 6 /rebootscript
30 17 22-28 * 6 /rebootscript

Please help me in understanding this.

Last edited by chidori; 08-14-2012 at 05:12 PM..
# 2  
Old 08-14-2012
Have you tried looking at your mailx to see if any errors occurred?
# 3  
Old 08-14-2012
From a syntax point of view, it should be something like this:

Code:
30 17 8-14 * * [ `date +\%u` -eq 6 ] && /rebootscript # to reboot every second saturday
30 17 22-28 * * [ `date +\%u` -eq 6 ] && /rebootscript # to reboot every fourth saturday



Quote:
30 17 8-14 * 6 /rebootscript
30 17 22-28 * 6 /rebootscript
These two do not work because you can only have one cron value defining "Day of Month" or they become cumulative. These examples would try to reboot the server twice at 17:30 every Saturday and also once every day on days 08-14 and 22-28 of the month.

Last edited by methyl; 08-14-2012 at 07:41 PM..
This User Gave Thanks to methyl For This Post:
# 4  
Old 08-14-2012
Hi ,

i got this solution from one of this forum post.

Code:
 
30 17 8-14,22-28 * * [ `date +\%u` -eq 6 ] && /rebootscript


So , will this also reboot the server on 2nd and 4th saturday ?
This User Gave Thanks to chidori For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Saturday May 4th the Forums Will Briefly Break Testing PHP 5.6 to PHP 7.0

On Saturday May 4th the forums will briefly break when I switch our Apache PHP 5.6 module to PHP 7.0. Previously, I had two sites set up for testing the migration, but for many reasons, the second site has additional issues unrelated to PHP 7.0 so it is hard to debug on a different site and... (3 Replies)
Discussion started by: Neo
3 Replies

2. UNIX for Beginners Questions & Answers

Schedule the cron job for every 21day on saturday

Please guide me how to schedule the cron job to run on every Saturday at 6am with the interval of 21 days. (2 Replies)
Discussion started by: raghavendrajsv
2 Replies

3. UNIX for Dummies Questions & Answers

How to Set crontab for 4th and 25th of every month?

Hello, I wanted to set Crontab for 4th and 25th of every month at 5:00 PM. Script should take previous month and current year as command line arguement like... /home/test1.sh -f ABCD 03 2014 so above script will run on 4th and 25th April 2014 but argument should be like previous month... (11 Replies)
Discussion started by: ajju
11 Replies

4. Shell Programming and Scripting

Scheduling on every 2nd Saturday of a Month

Hi ! I need ur help on a UNIX scheduling Concept understanding : If I need to schedule a job (Say ETL Datastage job) through a shell script using the Cron function to make it run on every second saturday of every month, How can I do it ? :confused: (2 Replies)
Discussion started by: Ravichander
2 Replies

5. Shell Programming and Scripting

Run cron on every second Saturday ??

Hi, Can anyone help in editing CRON (OR) write a script to run another script every second saturday?? I tried to make use of DATE command to find the day but couldnt proceed further. your help is highly appreciated! Thanks, Mahi (11 Replies)
Discussion started by: mahi_mayu069
11 Replies

6. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. UNIX for Dummies Questions & Answers

How to Set up a cronjob On 4th Sunday of every Month?

How to Set up a cronjob which will run On 4th Sunday of every Month at 8:00 PM :( (11 Replies)
Discussion started by: tp2115
11 Replies

8. UNIX for Dummies Questions & Answers

cron script -run every 2nd day of month except Monday

I know I can't schedule this in cron and would have to write a wrapper around my script and schedule it in cron ....but not sure how do to this? How do I exclude Monday if the 2nd day of the month falls on a Monday? Thanks. I tried this: 0 0 2 * 0,2-6 command And I know this doesnt... (2 Replies)
Discussion started by: newtou
2 Replies

9. UNIX for Advanced & Expert Users

How to scedule a script to be run on every second saturday in Month?

Hello Friends, In my project I have to schedule a script to be run on every second saturday (once in month). Can you please suggest what entry should I make in cron ? (5 Replies)
Discussion started by: sourabhsharma
5 Replies

10. Shell Programming and Scripting

Check if a day eg: saturday is the Last saturday of the month!

Hi, I need to develop a script to check for the day. If the day is a Saturday then the script should check if the Saturday is the last Saturday of the month so that certain set of instruction can be executed is it is the last Saturday. I do not want to use the crontab as this needs to be part... (9 Replies)
Discussion started by: jobbyjoseph
9 Replies
Login or Register to Ask a Question