Trigger the script if it is first sunday of the quarterly month


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trigger the script if it is first sunday of the quarterly month
# 8  
Old 12-30-2015
Quote:
Originally Posted by Arun1992
.
.
.[CODE].
.
.
Date=` date +%e `
Date_From_Calendar=` cal | awk 'NF==7 && !/^Su/{print $1;exit}' ` ---- This variable will store the first sundays date of the month.

if [[ $Date_From_Calendar-le 7 ]];
.
.
.
What keeps you from plainly trying Don Cragun's simple proposal?
Quote:
Originally Posted by Don Cragun
.
.
.
Code:
[ $(date +%e) -gt 7 ] && exit 0

.
.
.
# 9  
Old 12-30-2015
Code:
minute hour 1-7 3,6,9,12 0 command_string

Anyone would know a reason why this wouldn't do it? Since the day of the week is set as 0 (Sun) and the days of the month are 1 through 7 (for the first week), wouldn't 0 negate already any day that is not Sunday, out of those first seven days?
# 10  
Old 12-30-2015
man crontab :
Quote:
Note: The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren't *), the command
will be run when either field matches the current time. For example,
``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
This User Gave Thanks to RudiC For This Post:
# 11  
Old 12-30-2015
Since minute hour 1-7 3,6,9,12 0 command_string would run every day from 1 to 7 and also every Sunday, perhaps this might do it.
Code:
minute hour * 3,6,9,12 0 [ $(/usr/bin/date +%e) -le 7 ] && /path/to/script

# 12  
Old 12-30-2015
Quote:
Originally Posted by Aia
Since minute hour 1-7 3,6,9,12 0 command_string would run every day from 1 to 7 and also every Sunday, perhaps this might do it.
Code:
minute hour * 3,6,9,12 0 [ $(/usr/bin/date +%e) -le 7 ] && /path/to/script

Yes, this would do it. But it might be a bit "tidier" (for lack of a better word) to have everything in one place (like the scripts text) than spread over several places (part of the logic in cron, part of the logic in the script. If you put [ $(/usr/bin/date +%e) -le 7 ] && into the scripts text or into the commandline of the cron command should (otherwise) make no big difference.

At least this is my personal POV on the matter and maybe only makes sense because of the acquired style i work in. Technically there is no real difference and with another way of doing things the opposite may make equal sense.

I hope this helps.

bakunin
# 13  
Old 12-30-2015
Quote:
Originally Posted by bakunin
Yes, this would do it. But it might be a bit "tidier" (for lack of a better word) to have everything in one place (like the scripts text) than spread over several places (part of the logic in cron, part of the logic in the script. If you put [ $(/usr/bin/date +%e) -le 7 ] && into the scripts text or into the commandline of the cron command should (otherwise) make no big difference.

At least this is my personal POV on the matter and maybe only makes sense because of the acquired style i work in. Technically there is no real difference and with another way of doing things the opposite may make equal sense.

I hope this helps.

bakunin
Glad you mentioned that it was your opinion, since it is debatable. I could make the argument that since the time when it runs is related to the cron job, separating the actual work from it (the script) is more logical, in that way if I decided to run it the first Sunday and the third Sunday, I do not have to get involved with the script, but rather the facility that deals with the time. Also, if I am not who created the script and I am administering an issue in the box, related to this particular run job, I could right away see what and when it is trying to run, without having to delve into any script to find out. Now, this is my reasoning.

Last edited by Aia; 12-30-2015 at 04:14 PM.. Reason: Adding my reasoning
# 14  
Old 12-31-2015
I'll go with BakuninSmilie

If you can not instantly decipher the purpose of command in cron, that code should be in script.
In this case i would use a case condition in script.
Alternatively you could be passing argument in cron to script with desired condition ($1) which one could change in crontab directly.

This is just my opinion and has nothing to do with right and wrong.

Best regards
Peasant.
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. Shell Programming and Scripting

Run script on every last sunday of the month

Hi ALL, I have been testing this script to run for every last Sunday of the month,looks like month which have 5 sunday (july 2016 )is not passing this and failing every time. Here is what I am using, current_date=31 echo " CURRENT DAY -> $current_date" if ... (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Shell Programming and Scripting

How to setup cronjob 3rd sunday of every month?

Hi All, I need to set up cronjob for every third sunday of the month. here i have seen one example for 4th sunday for every month in another post and it looks perfect.can anyone please help me to understand this and help me to get the setup for third sunday of every month.Thanks. this is... (7 Replies)
Discussion started by: netdbaind
7 Replies

4. UNIX for Dummies Questions & Answers

Script should check and run only on Sunday

Hi All, I have a script, I want to make sure the script should check whether the day is sunday, only then it should run, if it is run other days it should check and exit the script. Kindly help. Thanks in Advance !! (41 Replies)
Discussion started by: nanz143
41 Replies

5. Shell Programming and Scripting

How to get first sunday of the month?

Hi, Please can someone help me in getting first sunday date of a month. i_year=`date +%Y` ny_first_sun_nov=`cal 10 $i_year | sed '/^$/d' |head -3 |tail -1| rev | cut -c1` This works good if the first sunday has a value but not if it is blank and first sunday falls on second week. ... (17 Replies)
Discussion started by: infyanurag
17 Replies

6. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

7. UNIX for Dummies Questions & Answers

Run script on every second sunday

I was to schedule a script in a crontab after every 15 days specically on every 2nd Sunday. I know that i can schedule on basis of weekdays, but can it be done by skipping in between???:wall: (5 Replies)
Discussion started by: masquerer
5 Replies

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

9. Shell Programming and Scripting

Shell Script to Handle Quarterly Backup.

Hi I'm not to shell script and I'm trying to write a simple shell code to do the following. Shell script should be run in March, June, Sept, & Dec respectively to back up files last modified in the 1st, 2nd, 3rd, and 4th quarters. I've have the following code. #!/bin/csh set v1 = `date... (1 Reply)
Discussion started by: Magshabib@gmail
1 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