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 for every 4th sunday of the month.
HTML Code:
cal | nawk 'FNR==3 {i=(NF<7)?1:0}FNR==(6+i){print $1}'
That will give you the date, its wont stop you having to test... (Is it the XX ?...)
So 2 options:
run every sunday and test if its the third or
run on 15-21 and test if the day is sunday
I agree with vbe's solution like we can run script on each Sunday and check either it is 3rd Sunday or not.
Following code may help you to get the 3rd Sunday with explaination.
Logic behind the code is if we need to get any 3rd occurance of a day(Sunday in this case) in a month it should come in 5th line of command cal output, but in case a month's starting day is not Sunday so number of fields NF will be less than 7 then. So by condition NF<7 we are checking the same and assigning a value of variable i. Now if number of fields are less than 7 means 1st day of a month is not Sunday so we need to jump to next line which is 6th line of command cal so we are doing here NR==(5+i) and checking if condition is true and printing it.
Hope this helps.
Thanks,
R. Singh
Last edited by RavinderSingh13; 10-29-2014 at 02:57 AM..
Reason: fine tune the lines
These 2 Users Gave Thanks to RavinderSingh13 For This Post:
Ravinder explanations was very clear,just for the curiosity if assume we want to get the date for every last i.e 4th/5th Thursday/Friday of the every month then what will be the code.
I tried something this but if assuming 4th/5th Thursday .I'm using this
I'm getting the same output.Please Help.
Last edited by netdbaind; 10-30-2014 at 05:26 AM..
OK, provided you have GNU date, use bash as a shell, and set the shell variable month to the desired month, this will be for May 2014
and this for November 2014
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)
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)
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)
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)
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)
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)
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)