Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to find the Last but one Friday of every month

Status
Not open for further replies.

naveenrt

Technical User
Mar 23, 2001
53
US
Hi All
Is there any one who has a readymade script to find the Last but one Friday of the month .

What i mean is the script should inteligently detect that 22 id the last but one friday of the month

I need this to run a special backup on the last but one friday of the month and the rest fridays normal backup would run

$ cal
November 2002
Sun Mon Tue Wed Thu Fri Sat
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


 
I would set up a file with the last Fridays recorded as Julian dates (i.e day of the year in numeric format e.g today is day 318 - 'date +%j') Do this for the next 5 years.

like;

326 2002
354 2002
etc
etc

In your backup script do something like

search for the julian date in your 5 year file
check its the right year
if its there do the special backup
if not.......

Alex
 
Here's an awk script that may help you.

cal | awk -f fri.awk

# ------ fri.awk ------
NR>2 {
if (NR==3) j = NF
if (NF) k = $NF
}
END {
f = j-1
if (f<1) f=7
while (f<=k) f+=7
print f-14
}
~
~ CaKiwi
 
CaKiwi
Great SCript . Thanks a lot for your help

[dazed]

Cheers
Naveen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top