- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- System Administration
- >
- Re: month end cronjob
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
- Email to a Friend
- 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
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP