- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Cron / Scheduling Problem
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
Forums
Discussions
Discussions
Discussions
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
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
11-27-2001 04:00 PM
11-27-2001 04:00 PM
I need to schedule a cron job to run every fourth Friday at 11:00 PM. I can make the the cron job run every Friday but when I try to use the week number in the date command, it doesn't always work when I go from one year to the next. Is there an easy answer for this?
Thanks in advance, Greg
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 04:15 PM
11-27-2001 04:15 PM
SolutionI have a deal for you. What you are going to do is turn todays date into a Julian Day. (~ the number of days since 4713 BCE). Astronomers use this method to make orbital calculations easy. I'll attach my caljd.sh to do all the hard work. I assume you already have the cron entry to fire off the command every Friday at 2300. We now just need to determine if this is the correct Friday and execute some command or simply exit. Try this:
#!/usr/bin/sh
GO_WK=0
# GO_WK should be in the range 0-3 depending
# on which week you wish to start this
export PATH=${PATH}:/usr/local/bin
STAT=0
WK=$(( (($(caljd.sh) + 1) / 7) % 4))
if [ ${GO_WK} -eq ${WK} ]
then
echo "Execute Command" # should set STAT
fi
exit ${STAT}
---------------------------
You should install caljd.sh in /usr/local/bin (or some other convenient place but set the PATH accordingly).
Now here's what it is doing.
We get the current Julian Day and add 1 to it. (that simply makes the weeks start on Sunday).
Next we integer divide by 7 to get the number of the week since 4713BCE. We then do a mod 4 to get a number in the range of 0 to 3 - just what you need.
You can execute cajld.sh -u for full usage.
Enjoy, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 04:28 PM
11-27-2001 04:28 PM
Re: Cron / Scheduling Problem
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 04:33 PM
11-27-2001 04:33 PM
Re: Cron / Scheduling Problem
Cron, in and of itself, isn't smart enough to do what you want. My approach would be to schedule a cron job at 23:00 every Friday. That job would run a script that verifies the day_of_month is 22 - 28. If so, run your job else edit.
That works because the 4th Friday (or any other day of the week) is always the 22nd - 28th.
Just saw Clay's solution which is much more elegant. I'm going to have to check it out to see how I can begin using it.
Anyway, you could use my method.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 04:53 PM
11-27-2001 04:53 PM
Re: Cron / Scheduling Problem
Darrell yours was good too but Clay's was perfect. I've been looking at his caljd.sh script and I can't begin to understand how it works but it does.
Thanks again, Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2002 07:06 AM
04-03-2002 07:06 AM
Re: Cron / Scheduling Problem
00 10 22-28 * 5
This would perform the desired function on the fourth friday of every month at 10:00.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2002 07:53 AM
04-03-2002 07:53 AM
Re: Cron / Scheduling Problem
You may be correct but I interpreted Greg's question to be every 4th Friday (i.e. 28 days) rather than the 4th Friday of a given month. This was hinted at by his attempt to use the week number in the date command but only Greg knows for sure.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2002 12:28 PM
04-03-2002 12:28 PM
Re: Cron / Scheduling Problem
Thanks for the response but Clay interpreted my question correctly. I apologize for being unclear. In our case, we have bi-weekly payroll runs and some special processing is done after every other payroll run rather than the fourth Friday of each month.
Greg