- 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 01:28 AM
тАО09-30-2004 01:28 AM
how to write a script to run last sunday in a month
Need some help to schedule a script to run last sunday in a month.
Thanks in advance.
TDN
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 01:36 AM
тАО09-30-2004 01:36 AM
Re: how to write a script to run last sunday in a month
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=707481
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 01:59 AM
тАО09-30-2004 01:59 AM
Re: how to write a script to run last sunday in a month
Thanks Geoff.
I think i do the easy way.
In my script the `date +%d` must be less than 22.
I try this first.
Regards
TDN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 02:00 AM
тАО09-30-2004 02:00 AM
Re: how to write a script to run last sunday in a month
Thanks Geoff.
I think i do the easy way.
In my script the `date +%d` must be greater than 22.
I try this first.
Regards
TDN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 02:05 AM
тАО09-30-2004 02:05 AM
Re: how to write a script to run last sunday in a month
There are date calculators abound. You can even find one in the forums here. Do a search for datecalc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 02:37 AM
тАО09-30-2004 02:37 AM
Re: how to write a script to run last sunday in a month
But we have to include lines on executable script to check weather
1> The day is equal to 22 and month is feb and year divisble by 4 ( leaf year) and exit from that script execution.
2> Check month 31 days, leaf year and check weather it is less than 25 there.
3> Check month 31 days, leaf year and check weather it is less than 24 there.
Execution of there check will not take more than 2 secs there. So that,
execute the script on crontab on 22-31 and the executed script checks the day settings and do execution / exit without execution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 02:49 AM
тАО09-30-2004 02:49 AM
Re: how to write a script to run last sunday in a month
# 1> feb month
if [[ $(date +'%m') -eq 02 && $(($(date +'%Y')%4))) -eq 0 ]]
then
if [[ $(date +'%e') -eq 22 ]]
# Don't do this
exit
fi
fi
# 2> 31 days month and augest (08) month
if [[ $(($(date +'%m)%2) -eq 1 || $(date +'%m) -eq 08 ]]
then
if [[ && $(($(date +'%Y')%4))) -eq 0 ]]
then
if [[ $(date +'%e') -le 24 ]]
# Don't do this
exit
fi
else
if [[ $(date +'%e') -le 23 ]]
# Don't do this
exit
fi
fi
fi
# 3> 30 days month
if [[ $(($(date +'%m)%2) -eq 0 && $(($(date +'%Y')%4))) -eq 0 ]]
then
if [[ $(date +'%e') -le 23 ]]
# Don't do this
exit
fi
else
if [[ $(date +'%e') -eq 22 ]]
# Don't do this
exit
fi
fi
fi
Keep the sequence, and do exit after logging message in log file if you want there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 02:51 AM
тАО09-30-2004 02:51 AM
Re: how to write a script to run last sunday in a month
Clay Stephenson's date hammer script is probably the best way to go. If you are interested in hacking another method, you could try this trick:
cal | tail -2 | head -1 | awk '{print $1}'
which will give you the date of the last Sunday of the current month.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 02:56 AM
тАО09-30-2004 02:56 AM
Re: how to write a script to run last sunday in a month
#***************************************************************
#
# Description : This script should be run in cron every sunday.
# It will execute the desired command on the last
# Sunday of the month
#*************************************************************
#*************************************************************
# GLOBAL VARIABLE DECLARATIONS
#*************************************************************
BASE=/usr/local/bin
MONTH=`date +%m`
YEAR=`date +%y`
DAY=`date +%d`
COMMAND=
#*************************************************************
# BEGIN FUNCTION SECTION
#*************************************************************
twenty_eight () {
if [ $YEAR = 04 ]
then
if [ DAY -gt 22 ]
then
$COMMAND
fi
else
if [ DAY -gt 21 ]
then
$COMMAND
fi
fi
}
thirty () {
if [ DAY -gt 23 ]
then
$COMMAND
fi
}
thirty_one () {
if [ DAY -gt 24 ]
then
$COMMAND
fi
}
case $MONTH in
01|03|05|07|08|10|12) thirty_one;;
04|06|09|11) thirty;;
02) twenty_eight;;
esac
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 03:42 AM
тАО09-30-2004 03:42 AM
Re: how to write a script to run last sunday in a month
# Check today's date equal to last sunday of current month
if [[ $(date +'%e') -ne $(cal | grep -v "^$" | awk '{ print $1 }' | tail -1) ]]
then
# exit
exit 1
fi
John. You are really great. I heard as " Think simple to do great" and found here. I wrote a big script lines but you showed your best here. Thanks for your guidance.
- Tags:
- cal