Run cron on every second Saturday ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run cron on every second Saturday ??
# 8  
Old 07-19-2012
Quote:
i need to skip 3rd saturday and run it on fourth saturday
I don't agree with Scott - oddball date selections like this are hard to maintain - FWIW:
You should not try to do that with a crontab entry. You need to set up a calendar file that has the dates, for the whole year or two, of every saturday you want to run.

something like this goes in crontab
Code:
30 10 * * 6  /path/to/myscript.sh > /path/to/log.`date +%Y%m%d`

The first line of your script checks the "saturday" file you created:
Code:
  grep -q "`date +%Y%m%d`" /path/to/saturdayfile.dat  ||  exit 0

# 9  
Old 07-19-2012
Run cron on every second Saturday ??

Awesome logic scottSmilie Really got amazed!!!

Thanks a ton for the solution.

-Mahi
# 10  
Old 07-19-2012
Quote:
30 10 * * 6 /path/to/myscript.sh
Another way to detect the alternate Saturdays (assuming that month-boundaries are irrelevant). Look at the week number in the year and decide if it is an odd or an even number.
Code:
# Near top of script /path/to/myscript.sh (after Shebang line)
odd=$(($(date +%V)%2))    # Week number in year, divide by 2, take remainder 
if [ $odd -eq 1 ]
then
        exit
fi
if [ $odd -eq 0 ]
then
       echo "Even numbered week"
fi
# Rest of script


Last edited by methyl; 07-19-2012 at 11:00 AM.. Reason: layout
# 11  
Old 07-19-2012
There are a ton of books on this subject - keeping code and business rules separated.
I work on a huge CIS which does not do that. I get a lot less sleep as a result.
So this kind of thing is a hot button for me. Dates are the very worst part of this deal, IMO.

While scott's approach is correct, a priori, the next guy may not know what the heck those gyrations are for. 90% of coding is done by the 'next guy'.

What happens when the OP finds out he has to skip the Saturday after some holiday?
Lots of holidays work on a lunar calendar, BTW. And many holidays are based on a separate non-Gregorian calendar, e.g. Hijri, Hebrew, etc. In Israel the Knesset decides when daylight savings time starts, and they sometimes do it a posteriori. Good Luck.

Just my point of view.
# 12  
Old 07-19-2012
Unless there is a clear regular pattern, I usually set up a block of individual crons once a year. This covers abstract date patterns like Finance Month-End. It is also easy to adjust if there are exceptions such as hardware failure.
Jim's method is probably easier to maintain, but I prefer to have the whole schedule visible in crontab.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

4. Shell Programming and Scripting

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 30 17 8-14 * * if ; then /rebootscript; fi # to reboot every second saturday 30 17 22-28 * * if ; then /rebootscript; fi # to reboot every fourth saturday I am wondering why it... (3 Replies)
Discussion started by: chidori
3 Replies

5. Shell Programming and Scripting

Run webpage from cron

I am running into a issue. How would you run a http:// page from cron? I tried directly from cron but no luck. I tried a sh script with no luck. #!/bin/sh PERL_PATH=/usr/bin/perl $PERL_PATH "/fullpath/cgi-bin/search/indexer.cgi?login=indexer&pwd=spider" and #!/bin/sh... (1 Reply)
Discussion started by: mrlayance
1 Replies

6. UNIX for Dummies Questions & Answers

cron does not appear to run

Hi everyone, I am having a problem with a cron, I am using Solaris 10 and need to run a php file every 5 minutes. I can run the file from the test user, but the cron does not seem to run. I do not see anything about it in /var/cron/log but see crons for other users running. What should I look... (10 Replies)
Discussion started by: atomicbits
10 Replies

7. 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

8. Shell Programming and Scripting

Help with script - run by cron

Hello, I have a shell script that runs every minute to process incoming files delivered externally via SFTP to a directory. Basically the script works and processes the files however I get an error when a new file is delivered into the directory. Please see my script below. A new file is... (2 Replies)
Discussion started by: richo king
2 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Where does cron run from?

I have a script in the same directory as some files and directories im trying to tar up and I have it run in cron. Well it runs but says it can't find the directories, you need to be in the directory where the script is for it to work. Here is my cron and script its crappy but it does the trick =).... (3 Replies)
Discussion started by: kingdbag
3 Replies
Login or Register to Ask a Question