- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- month end cronjob
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
тАО02-28-2011 11:30 AM
тАО02-28-2011 11:30 AM
month end cronjob
I want to schedule a cronjob which should run every month end(last day of every month) 10 PM.
But with every month last date is varies.How i can achieve the same.
Please suggest
Regards
himacs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2011 11:47 AM
тАО02-28-2011 11:47 AM
Re: month end cronjob
end of month cron +site:itrc.hp.com
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2011 12:11 PM
тАО02-28-2011 12:11 PM
Re: month end cronjob
You could just make 3 crontab entries. And handle Feb 29 special every 4 years.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2011 01:10 PM
тАО02-28-2011 01:10 PM
Re: month end cronjob
You can let your script execute every day and test for the end-of-month this way:
# [ "$(date +%d)" = "$(cal|awk 'NF>0 {LAST=$NF};END{print LAST}')" ] && echo last_day || echo skip_it
As usual, TMTOWTDI
...which Google, as Pete suggested, will expose.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2011 03:58 PM
тАО02-28-2011 03:58 PM
Re: month end cronjob
1 1 28.29.30,31 * * myscript
Then in your script, use cal to locate the last day of the month:
LASTDAY=$(echo $(cal) | awk '{print $NF}')
[[ $(date '+%e') -ne $LASTDAY ]] && exit
So when the script runs, it will exit immediately if today's day of the month is not the last day. This method always works since the cal command does all the work handling days in each month, leap years, etc.
The cal command prints a formatted month but when used with echo, it is a string of numbers with the last number always the last day.
Bill Hassell, sysadmin