How to get first sunday of the month?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get first sunday of the month?
# 1  
Old 05-08-2013
How to get first sunday of the month?

Hi,

Please can someone help me in getting first sunday date of a month.

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

cal -m where I can make Monday as first day of the week so that Sunday always have a value does not work on Solaris.

Please can someone help me to get this corrected?

Thanks

Last edited by Scott; 05-08-2013 at 12:15 PM.. Reason: Code tags, PLEASE!
# 2  
Old 05-08-2013
I noticed that you opened several threads lately regarding date arithmetic and you didn't apply any suggestions posted in your previous threads!

Before going forward I suggest you to refer this thread in FAQ section.
# 3  
Old 05-08-2013
Thanks Yoda,

I will close the other threads with suggestions and comments,
All the threads correspond to different questions/ arithmetic but I should close them if they are resolved.

Thanks again
# 4  
Old 05-08-2013
Try ..

Code:
cal 12 2012 | awk 'NF==7 && !/^Su/{print $1;exit}'

This User Gave Thanks to clx For This Post:
# 5  
Old 05-08-2013
Its not working,

cal 12 2012 | awk 'NF==7 && !/^Su/{print $1;exit}'

is giving me S
I am looking for value that is 1
# 6  
Old 05-08-2013
That's working for me.

Code:
$ cal 1 2012 | awk 'NF==7 && !/^Su/{print $1;exit}'
1
$

Code:
$ cal 1 2012
    January 2012
Su Mo Tu We Th Fr Sa
 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

Please use /usr/xpg4/bin/awk on solaris
Also, post the output of
Code:
cal 1 2012

# 7  
Old 05-08-2013
cal 1 2012
January 2012
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 1 2012 | awk 'NF==7 && !/^Su/{print $1;exit}'

S

---------- Post updated at 10:00 PM ---------- Previous update was at 09:58 PM ----------

Quote:
Originally Posted by infyanurag
cal 1 2012
January 2012
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 1 2012 | awk 'NF==7 && !/^Su/{print $1;exit}'

S
/usr/xpg4/bin/awk

this is also giving me S
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. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

6. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

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

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. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 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