- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Crontab entries to run every 14 days
Operating System - HP-UX
1820545
Members
2346
Online
109626
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО08-03-2001 04:41 AM
тАО08-03-2001 04:41 AM
Is there a way to enter a job into crontab that will run every x number days, or every other Wednesday?
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2001 05:07 AM
тАО08-03-2001 05:07 AM
Re: Crontab entries to run every 14 days
Daryl,
I can not think of a way to do this via crom , but you may be able to do it using at instead.
Write a script as follows and call it a dummy name e.g
/usr/local/bin/atsubmit.sh:
echo "sh /usr/local/bin/atsubmit.sh" | at now + 14 days
./actual_programme
exit 0
Now setup the initial at job, e.g.
echo "sh /usr/local/bin/atsubmit.sh" | at 2000 Aug 12.
This will now submit a job to run at 8pm on 12 August 2001 and becuase the first thing the script does is to re-submit itself it should then continue to submit itself at 8pm every 2nd Sunday (12 Aug is a Sunday)
I know this doers not answer your question but it is a work around
I can not think of a way to do this via crom , but you may be able to do it using at instead.
Write a script as follows and call it a dummy name e.g
/usr/local/bin/atsubmit.sh:
echo "sh /usr/local/bin/atsubmit.sh" | at now + 14 days
./actual_programme
exit 0
Now setup the initial at job, e.g.
echo "sh /usr/local/bin/atsubmit.sh" | at 2000 Aug 12.
This will now submit a job to run at 8pm on 12 August 2001 and becuase the first thing the script does is to re-submit itself it should then continue to submit itself at 8pm every 2nd Sunday (12 Aug is a Sunday)
I know this doers not answer your question but it is a work around
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-03-2001 06:15 AM
тАО08-03-2001 06:15 AM
Solution
Hi Daryl:
There is not a way to do this directly with cron but there is a way to handle this within your script itself. The cron job is started every Wednesday but your script decides if the week is odd or even. The key to this is convert
today's date to a Julian Day. Divide that by 7 to get a julian week and mod that by 2 to get 0 or 1. You then execute if 1 and do nothing if 0 (or vice versa).
Inside your cron script:
#!/usr/bin/sh
JDAY=`/usr/loca/bin/caljd.sh/`
JWK=$((${JDAY} / 7))
IS_WK=$((${JWK} % 2))
if [ ${IS_WK} -eq 1 ]
then
echo "Do your thing"
else
echo "Do nothing"
fi
I've attached the caljd.sh script. This method will work year in/year out regardless of the number of weeks per year or days per year.
Regards, Clay
There is not a way to do this directly with cron but there is a way to handle this within your script itself. The cron job is started every Wednesday but your script decides if the week is odd or even. The key to this is convert
today's date to a Julian Day. Divide that by 7 to get a julian week and mod that by 2 to get 0 or 1. You then execute if 1 and do nothing if 0 (or vice versa).
Inside your cron script:
#!/usr/bin/sh
JDAY=`/usr/loca/bin/caljd.sh/`
JWK=$((${JDAY} / 7))
IS_WK=$((${JWK} % 2))
if [ ${IS_WK} -eq 1 ]
then
echo "Do your thing"
else
echo "Do nothing"
fi
I've attached the caljd.sh script. This method will work year in/year out regardless of the number of weeks per year or days per year.
Regards, Clay
If it ain't broke, I can fix that.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP