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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to Set up a cronjob On 4th Sunday of every Month?
# 1  
Old 07-12-2010
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 Smilie
# 2  
Old 07-12-2010
There is much variety in cron. Please post your Operating System and version.
# 3  
Old 07-12-2010
YMMV:
Code:
0 20 * * * [ `date +%d` -eq `cal | nawk 'FNR==3 {i=(NF<7)?1:0}FNR==(6+i){print $1}'` ] && doMyScript


Last edited by vgersh99; 07-12-2010 at 11:29 AM..
# 4  
Old 07-12-2010
@vgersh99

Interesting idea, but I think that will only work if the first of the month is a Sunday.
For this month it finds the 3rd Sunday.

Code:
cal
   July 2010
 S  M Tu  W Th  F  S
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

cal | awk 'FNR==6{print $1}'
18

# 5  
Old 07-12-2010
Quote:
Originally Posted by methyl
@vgersh99

Interesting idea, but I think that will only work if the first of the month is a Sunday.
For this month it finds the 3rd Sunday.

Code:
cal
   July 2010
 S  M Tu  W Th  F  S
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

cal | awk 'FNR==6{print $1}'
18

Thanks, I've also noticed this and fixed the code.
Good catch.
# 6  
Old 07-12-2010
My beautifully long-winded way of finding the same figure.
There has to be a better way.
Tested for various easy and awkward months.

Code:
# Day of fourth Sunday based on "cal"
for TRY in "02 2004" "02 2009" "02 2010" "07 2010" "08 2010" "09 2010"
do
        echo "======================"
        cal ${TRY}
        cal ${TRY} | sed -n '3,$ p'|cut -c1-2|grep -v "  "|head -4|tail -1
        echo "======================"
done


======================
   February 2004
 S  M Tu  W Th  F  S
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29

22
======================
======================
   February 2009
 S  M Tu  W Th  F  S
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28


22
======================
======================
   February 2010
 S  M Tu  W Th  F  S
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28

28
======================
======================
   July 2010
 S  M Tu  W Th  F  S
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

25
======================
======================
   August 2010
 S  M Tu  W Th  F  S
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

22
======================
======================
   September 2010
 S  M Tu  W Th  F  S
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

26
======================



UPDATE: Just tried "vgersh99" revised version and is gets the same answer in much less code!

Code:
cal | nawk 'FNR==3 {i=(NF<7)?1:0}FNR==(6+i){print $1}'


Last edited by methyl; 07-12-2010 at 11:57 AM.. Reason: UPDATE ...
# 7  
Old 08-19-2010
Code:
1 0 22-28 * 0 /path/to/script.sh

minute=1
hour=0
date range=22-28
month=all
day of week=sunday

the 4th Sunday of every month always falls in that date range.

Last edited by Yogesh Sawant; 08-27-2010 at 09:44 AM.. Reason: added code tags
 
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

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

Hello All, I have script which needs to be scheduled in crontab which needs to be run only on the first sunday of the quarterly months (March, June, September,Dec). Can anyone please help me out on this. Thanks, Arun. (13 Replies)
Discussion started by: Arun1992
13 Replies

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

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

6. UNIX for Dummies Questions & Answers

How to create a cronjob for the 3rd business day of every month?

Hello, Can you please help me out in creating a cronjob that runs every 3rd business day of the month. Thanks (2 Replies)
Discussion started by: AReddy
2 Replies

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

8. Solaris

Cronjob doesnot exist on the machine but running every sunday

I have deleted a particular cronjob couple of months ago but the jb is still running every sunday, even though it is not present in /var/spool/cron/crontabs/root file. Please assist. (6 Replies)
Discussion started by: prash358
6 Replies

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

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