- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- HP-UX Cron - run every first thursday of the month
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
10-06-2015 04:18 AM
10-06-2015 04:18 AM
Hello,
I'm trying to cron something to run every first thursday on the month, but is not working properly.
I have:
0 10 1-7 * 4 /home/myscript > /dev/null 2>&1
so it should run at 10am, between day 1 and 7 of everymonth if weekday is 4 (thursday).
Instead it is runing everyday if 1-7....
Why not respecting the weekday?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2015 06:16 AM
10-06-2015 06:16 AM
Re: HP-UX Cron - run every first thursday of the month
> Why not respecting the weekday?
If cron does day-of-month OR day-of-week (man cron), then it won't do
day-of-month AND day-of-week.
The usual solution for problems like this is to get cron to do the
best it can, and then add tests in the script to skip the unwanted
cases. For example, tell cron to run the script _every_ Thursday, and
have the script look for the _first_ Thursday. (Use "date", and look
for a day-of-month from 1-7.)
A Forum (or Web) search for keywords like, say:
cron day
should find many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2015 09:39 AM
10-06-2015 09:39 AM
Re: HP-UX Cron - run every first thursday of the month
Added in the top of the script:
chk_day=`date +%a`
if [ $chk_day = 'Thu' ];
then
my code
else
exit 0;
fi
Kept in the cron every 1-7 day in each month.
and it seems it is working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2015 11:41 AM - edited 10-06-2015 11:42 AM
10-06-2015 11:41 AM - edited 10-06-2015 11:42 AM
Solution>Kept in the cron every 1-7 day in each month.
Yes, that makes the script easier.
>chk_day=`date +%a`
If you're worried about locales, you may want a day of the week in numeric format:
chk_day=$(date +%u) # 1 - 7 Mon .. Sun
if [ $chk_day != 4 ]; then # Thu
exit # if not Thursday, exit
fi
I hope you have comments in both crontab and the script to indicate how they work together.