- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to write a script to run last sunday in a ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 03:54 AM
тАО09-30-2004 03:54 AM
Re: how to write a script to run last sunday in a month
cal | cut -c1-2|grep -v "^$"|tail -1 will give the date of the last sunday.
Now you have the date, set the script.
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 03:57 AM
тАО09-30-2004 03:57 AM
Re: how to write a script to run last sunday in a month
Thanks for the praise. I like to keep things simple. I'm too lazy to do all that hard thinking! :)
You can modify your code just slightly and get the last day of the month for any weekday. Just move the 'grep' after the 'awk', so that the blank lines are removed after the dates are printed. For example, to test for the last Friday of the month, this would work:
if [[ $(date +'%e') -ne $(cal | awk '{ print $6}' | grep -v "^$" | tail -1) ]]
Then you just adjust the variable in the awk print statement for the day of the week you want ($1 through $7 for Sunday through Saturday).
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 03:58 AM
тАО09-30-2004 03:58 AM
Re: how to write a script to run last sunday in a month
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 08:23 AM
тАО09-30-2004 08:23 AM
Re: how to write a script to run last sunday in a month
#!/usr/bin/sh
export PATH=${PATH}:/usr/local/bin
if [[ $(caljd.sh -M) -eq $(caljd.sh -n 7 -M) ]]
then
exit 0
else
echo "Last Sunday in month; do your thing"
fi
The idea is that that it looks at the current day's month and compare's it to that 7 days hence. If they differ, it's the last time that weekday occurs in the month.
By the way, caljd.sh -N will yield the occurence of a given weekday within the month.
Invoke as caljd.sh -u for full usage and examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 11:14 AM
тАО09-30-2004 11:14 AM
Re: how to write a script to run last sunday in a month
I was stunned by that one liner but that's a great try. For ex.,
cal 08 04 |tail -2 |head -1 |awk '{print $1}'
is not giving me the last sunday ;-).
I believe the best approach is given by Clay. We use similar logic here where some of our maintenance windows are on 2nd Sunday!!. Add 7 to the current date and if the resulting date is of next month, then that's it. Run it every sunday.
#!/usr/bin/ksh
NOW=$(/usr/contrib/bin/perl -e "printf("%d\n",time())")
MON=$(date +%b)
(( NEXTMON_SECS = $NOW + ( 7 * 86400 ) ))
NEXTMON=$(echo "0d${NEXTMON_SECS}=Y" |adb |awk '{print $2}' )
if [[ "$MON" != "$NEXTMON" ]]
then
echo "OK!.. this is the last sunday."
#your_function
else
echo "More sundays to go"
exit 0
fi
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2004 12:43 AM
тАО10-01-2004 12:43 AM
Re: how to write a script to run last sunday in a month
August 4
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 08 04 | cut -c1-2|grep -v "^$"|tail -1
31
Looks like last Sunday to me...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2004 12:45 AM
тАО10-01-2004 12:45 AM
Re: how to write a script to run last sunday in a month
# cal 08 2004 | cut -c1-2|grep -v "^$"|tail -1
29
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2004 01:12 AM
тАО10-01-2004 01:12 AM
Re: how to write a script to run last sunday in a month
Thank you all of you.
I think I go for the solution to put the script in cron running every sunday and check out if the date is the last sunday inside the script.
I found a example on bigadmin.com
Once again, thanks guys.
Regards
TDN
- « Previous
-
- 1
- 2
- Next »