Crontab job on sunday with two week interval


 
Thread Tools Search this Thread
Operating Systems AIX Crontab job on sunday with two week interval
# 1  
Old 03-19-2008
Crontab job on sunday with two week interval

Hi experts,

Please help me to set a backup script run at 6AM on Sunday every two week
It means
the 1st sunday, run script backup at 6AM
the 2nd sunday, skip
the 3rd sunday, run script backup at 6AM
the 4nd sunday, skip
... so on

Thank you so much
# 2  
Old 03-19-2008
I don't think that this is possible by only crons means (at least not to my knowledge). What you could do is put something into the script which makes it run the "action"-part only every other run:

Code:
#! /bin/ksh

if [ -e /some/file ] ; then
     rm -f /some/file
else
     touch /some/file
     exit 0
fi

... do here what your script is supposed to do ....

exit 0

On the first run the script will not find /some/file, so it will create it and exit. On the second run it will remove it and then proceed to do whatever it is supposed to do. On the next run it won't find the file (because it removed it) and therefore will only create it and then exit, ....

This script can be used weekly in cron but will do its intended purpose only every other week.

I hope this helps.

bakunin
# 3  
Old 03-19-2008
Or you could just map out what date every other sunday will be for the rest of the year and put those dates in the cronjob. Then do the same thing at the end of the year.
# 4  
Old 03-19-2008
You'd think that the crontab line would be something like this:

[minute] [hour] 1-7,15-24 * 0 [function]

I.E. You're saying run the function at the time specified every Sunday of every month, when the date is 1st thru 7th or 15th thru 24th.

This creates two problems:

A - Because of a quirk in cron, the job will actually run EVERY Sunday AS WELL AS every day from the 1st to the 7th and 15th to the 24th.
B - If that quirk did not exist, you'll miss a week when there are 5 Sundays in the month (this may or may not be a problem for you),

Simple solution:

Have cron run it EVERY Sunday. Then have your script either check the current date, assuming you want to skip the 5th Sunday of the month), or check and set a flag in a file to indicate if it ran that week or not.


Note: This second idea is essentially what Bakunin said.
# 5  
Old 03-20-2008
Thank bakunin and other experts
Your ideas is excellent, i set it already
Regards


Quote:
Originally Posted by bakunin
I don't think that this is possible by only crons means (at least not to my knowledge). What you could do is put something into the script which makes it run the "action"-part only every other run:

Code:
#! /bin/ksh

if [ -e /some/file ] ; then
     rm -f /some/file
else
     touch /some/file
     exit 0
fi

... do here what your script is supposed to do ....

exit 0

On the first run the script will not find /some/file, so it will create it and exit. On the second run it will remove it and then proceed to do whatever it is supposed to do. On the next run it won't find the file (because it removed it) and therefore will only create it and then exit, ....

This script can be used weekly in cron but will do its intended purpose only every other week.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

cron job on 3rd sunday of every month

Hi, Actually scheduled my test scripts on test severs as shown below. They are supposed to run on 3rd sunday of every month. Unfortunately it ran on 2nd sunday of the month (suspecting that it will run every sunday). I am sorry if I miss something. Could you please let me know if I did any... (1 Reply)
Discussion started by: System Admin 77
1 Replies

2. UNIX for Advanced & Expert Users

Autosys job run on Sunday

Hi, I need to create a autosys job which will run on every sunday at 7:30 AM NY time for each 10 min interval of time. days_of_week: su start_mins: 0,10,20,30,40,50 run_window:"07:30" Is it fine? Please help Thanks, Anup (2 Replies)
Discussion started by: anupdas
2 Replies

3. UNIX for Advanced & Expert Users

Use cron to run job every other week

my colleague was asking about this: is there a way to run a cron job biweekly, like a script five.sh to run every *OTHER* Friday within November its part about every other Friday we cant find any documentation. thx L (8 Replies)
Discussion started by: lydiaflamp
8 Replies

4. UNIX for Dummies Questions & Answers

Crontab running every alternative sunday

Hi, I want to run a script starting this 28 Mar 2010 every alternative sunday. Can you give me the crontab entry for the same. Mine is a HP unix. (2 Replies)
Discussion started by: Krrishv
2 Replies

5. UNIX for Dummies Questions & Answers

crontab every other week

I have two sets of tapes for each week days. Mon_Set_A ____________Tue_Set_B Tue_Set_A ____________ Tue_Set_B Wed_Set_A ___________ Wed_Set_B Thr_Set_A ____________ Thr_Set_B Fri_Set_A _____________ Fri_Set_B I have script that does cold backup of database and then back up to tape. ... (1 Reply)
Discussion started by: Paul.S
1 Replies

6. Shell Programming and Scripting

Cron job for wekkly interval

Hi, I would like to trigger a scipt on every Wednesday 12:00PM. how can schedule this script in CRON command. Could you please help me on this. (3 Replies)
Discussion started by: koti_rama
3 Replies

7. Shell Programming and Scripting

run script 1 minute interval without CronTab

I am using Solaris 9. I wish to run my script every 1 minute inteval. Though i can run it using below entry in crontab. * * * * /export/home/username/script/file_exist_&_run.sh in short above script will check whether a specific file exist in a directory. If it found it will inovke another... (10 Replies)
Discussion started by: thepurple
10 Replies

8. Shell Programming and Scripting

Crontab job to run every sunday

Hello, I wanted to run one of my shell script for every sunday at 5PM. Here is the crontab entry i am using.. 00 17 * * 0 /inventory/update.sh > /inventory/update.log 2>&1 The job is not kicking on sunday at the specified time.. Am i missing anthing? Any help is appreciated... (2 Replies)
Discussion started by: govindts
2 Replies

9. UNIX for Dummies Questions & Answers

crontab every 2 minutes, 24 hours and once a week

can someone please check my answers for the crontabs I am making 1. how would I set up a crontab tab executes every 2 minutes each and every day of the week? answer: 2 * * * * /path/to/file.pl <-- is this correct? 2. how would I set up a crontab that executes every 24 hours at 2am?... (6 Replies)
Discussion started by: Bobafart
6 Replies

10. UNIX for Dummies Questions & Answers

Cron job -- to execute at every first Sunday of every month

Dear all How can I schedule the cronjob to be run sometime at every first Sunday at every month? I have the edit the cronjob every month now, thanks (2 Replies)
Discussion started by: shanemcmahon
2 Replies
Login or Register to Ask a Question