Cron job every Friday except 4th


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cron job every Friday except 4th
# 15  
Old 04-23-2010
Cheers for the replies.

I have a few test things set up in the cron of a test UNIX box to see how they go, executing writing to files rather than running any backups.

Will see over the next few weeks. No rush to implement this in live environment.

Cheers,
Rab
# 16  
Old 04-23-2010
Quote:
Originally Posted by alister
Instead of "-gt 0", "-eq 3" should harmonize with the echo statements.
Not exactly Smilie 21 will be on the fourth and 28 on the fifth.
I think this will do the job:
Code:
var=$(date +%j)
if [ $(date +%u) -eq 5 ] && [ $((($var / 7) % 4))$(($var%7)) -gt 30 -o $((($var / 7) % 4))$(($var%7)) -eq 0 ];then echo fourth week ;else echo regular week;fi


Quote:
Originally Posted by frans
[/LIST] You can use the +%U format which gives the week number (as i posted above).
Code:
(( $(date +%U) % 4))

will return false 1/4 and true 3/4
Yep but will start on Sunday Smilie
Quote:
%U week number of year, with Sunday as first day of week (00..53)
# 17  
Old 06-25-2010
Hi again!

Still trying to get this to work, I have let it run for a while now and here is the results:

Code being run every Friday:
Code:
var=$(date +%j)

if [ $(date +%u) -eq 5 ] && [ $((($var / 7) % 4))$(($var%7)) -gt 30 -o $((($var
/ 7) % 4))$(($var%7)) -eq 0 ];

then echo Monthly Backup Ran >> /rab/testing.txt ;

else echo Weekly Backup Ran >> /rab/testing.txt;

fi

Output from testing.txt (note - I have manually added lines to this to keep track of dates):

Quote:
# FIRST CRON DATE - 30th April 2010 (Should be MONTHLY)
Weekly Backup Ran

Next one is 7th -
Weekly Backup Ran

Next one is the 14th -
Monthly Backup Ran

21st -
Weekly Backup Ran

28th This one should be a MONTHLY-
Weekly Backup Ran

4th June -
Weekly Backup Ran

11th June -
Monthly Backup Ran

18th June -
Weekly Backup Ran
Here you can see that the script is running once every 4 weeks, but it just falls on the wrong date.

So I'm guessing I need to offset the remainder it looks for (-eq 0) to something else? To offset it by 2 weeks. As it is out of sync by 2 weeks.

Tonight is a "Monthly backup" week(end).

Any ideas?
Cheers,
Rab
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Cron - job to run every 3rd Friday of the month only

Hi Expert Please help me to set a cron job schedule, Ihave a job that run every 3rd Friday of the month at 1030am. I tried to set up like this, but the job still runs every friday at 1030am. I want the job to run every 3rd Friday of the month at 1030am only 30 10 15,16,17,18,19,20,21... (2 Replies)
Discussion started by: kaibiganmi
2 Replies

4. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

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

6. Shell Programming and Scripting

cron job to run on second to last friday each month

I needed a cron job to run on the second to last friday of every month. Our servers are running HP-UX, and the HP-UX date command is pretty basic and does not have all of the fancy options that Linux date command does, and it does not have the ability at all to return future dates. So I had to... (0 Replies)
Discussion started by: lupin..the..3rd
0 Replies

7. UNIX and Linux Applications

Help regarding a cron job

Hi, I need to write cron job, which tries to build a project. It would check out code from a repository and then will attempt to build it .The results of the build would show up on a web-page (a table with rows, one for each build, should get updated; a link to the detailed log file; color green... (3 Replies)
Discussion started by: sat411
3 Replies

8. UNIX for Dummies Questions & Answers

cron job

Hi, How to monitor whether a cron job is running or errored out..?other than checking the process using ps-aef how to enter the cron job which throws the output in 1 file and errors in other file. i remember it can be done using >1 and >2 ..but not sure.. any expert..please help!! (1 Reply)
Discussion started by: rujus
1 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. UNIX for Dummies Questions & Answers

CRON usage for CRON job

can anybody explain the usage of CRON for adding a cron job. please provide an example also for better understanding !!! Thanks (1 Reply)
Discussion started by: skyineyes
1 Replies
Login or Register to Ask a Question