Check if a day eg: saturday is the Last saturday of the month!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check if a day eg: saturday is the Last saturday of the month!
# 8  
Old 12-21-2006
totrow=`cal $1 2006 |grep -v "^$"| wc -l`

cal $1 2006 | grep -v "^$"|nawk -v rowcount="$totrow" -v inday="$2" '{if(NR == r
owcount){
day="sun mon tue wed thu fri sat"
split( day, weekday," ")
if ( weekday[NF] == inday) {
print inday " is last in month"
}
else {
print inday " is not last in month"
}

}}'

This is for last
# 9  
Old 12-21-2006
cal $1 2006 | nawk -v inday="$2" '{ if( NR == 3 ){
daycount= 8 - NF
day="sun mon tue wed thu fri sat"
split( day, weekday," ")
print weekday[daycount]
if( weekday[daycount] == inday ) {
print inday " is first day of the month"
}else {
print inday " is not first day of the month"
}
}}'

to get first day
# 10  
Old 12-22-2006
Alternative with GNU date and bash shell.

Check if today's week day is the last of the month
Code:
[ $(date  --date '7 days' +%m) != $(date +%m)  ] && echo "last"

Check if the week day of a particular date is the last of the month
Code:
[ $(date  --date '2006-12-22 7 days' +%m) != $(date --date '2006-12-22' +%m)  ] && echo "last"


Last edited by ripat; 12-22-2006 at 03:34 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check day name is it saturday in bash shell script?

How to check the day name,is it saturday in bash shell script. If dayname = saturday then run the full load else run just the incremental loads end if Thank you very much for the helpful information. (4 Replies)
Discussion started by: cplusplus1
4 Replies

2. Shell Programming and Scripting

Scheduling on every 2nd Saturday of a Month

Hi ! I need ur help on a UNIX scheduling Concept understanding : If I need to schedule a job (Say ETL Datastage job) through a shell script using the Cron function to make it run on every second saturday of every month, How can I do it ? :confused: (2 Replies)
Discussion started by: Ravichander
2 Replies

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

4. Shell Programming and Scripting

Run cron on every second Saturday ??

Hi, Can anyone help in editing CRON (OR) write a script to run another script every second saturday?? I tried to make use of DATE command to find the day but couldnt proceed further. your help is highly appreciated! Thanks, Mahi (11 Replies)
Discussion started by: mahi_mayu069
11 Replies

5. Windows & DOS: Issues & Discussions

How to get next Saturday's 'Date'?

Hi am trying to get the upcoming Saturday date in the batch file. Kindly help ASAP. its urgent. :confused: (10 Replies)
Discussion started by: Zensar
10 Replies

6. UNIX for Advanced & Expert Users

How to scedule a script to be run on every second saturday in Month?

Hello Friends, In my project I have to schedule a script to be run on every second saturday (once in month). Can you please suggest what entry should I make in cron ? (5 Replies)
Discussion started by: sourabhsharma
5 Replies

7. Shell Programming and Scripting

Searching for a file, with name Last Sunday through Saturday

Hi List, I need write a script that looks for a file with name File_03-09_to_03-15_data.txt (File_LastSunday_to_LastSaturday_data.txt). If this file is not exists i have to look for a pervious weeks file like File_03-02_to_03-08_data.txt. This loop should continue untill it get a file or no file... (0 Replies)
Discussion started by: rejirajraghav
0 Replies

8. Solaris

How to check for Saturday or Sunday

Hi , I have a date parameter passed in YYYYMMDD format , how can I check whether it is Sat or Sun on Solaris box , as we can do the same easily on linux box by using date -d YYYYMMDD '+a' . Any pointres will be really helpful . (5 Replies)
Discussion started by: harpreetanand
5 Replies

9. Shell Programming and Scripting

Date - Last Sunday thru Saturday

Hi All, I have to kick off a script on every Monday to get some data from database for last week (Sunday thru Saturday). If its Monday (12/12/2005) Begin date will be Sunday - 12/4/2005 End date will be Saturday - 12/10/2005 The script might not kick off on some Mondays. So my... (2 Replies)
Discussion started by: skymirror
2 Replies
Login or Register to Ask a Question