- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to setup cron to run on second sunday of the m...
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
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
тАО09-28-2004 03:56 PM
тАО09-28-2004 03:56 PM
This is my first time to log a question on the forum hope you can help me on this. We're thinking to have this cron entry "0(min) 8(hour) 8-14(day_of_month) 2,4,6,8,10,12(even month) 0(Sunday) command", but there some issue on our team that with this setup it will run from 8th to 14th even though not everyday is a sunday. Also, if we use this method then we will have to check it every year to make sure they are still correct.
Basically we just want to run the script every second sunday of the month.
Thanks in advance to all who will help us on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 04:35 PM
тАО09-28-2004 04:35 PM
Re: How to setup cron to run on second sunday of the month?
0 8 8-14 2,4,6,8,10,12 0 test `/usr/bin/date +\%w` -eq 0 && your_script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 05:34 PM
тАО09-28-2004 05:34 PM
Re: How to setup cron to run on second sunday of the month?
1. What entry should I put if I want to put a cronjob to reboot my server on every second sunday of the month.
2. or every second sunday of even month.
Tkhs....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 06:08 PM
тАО09-28-2004 06:08 PM
Re: How to setup cron to run on second sunday of the month?
Not an answer on your question but... Why do you want to perform a reboot with a crontab entry?
A reboot must only be done when it is required (eg kernel rebuild, installation of a new patch, ...) and shouldn't be done preventive, it isn't a Windows box.
And if I reboot a server, I want to follow the boot process myself or at least check that the server is up and running again.
best regards,
Kurt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 06:22 PM
тАО09-28-2004 06:22 PM
Re: How to setup cron to run on second sunday of the month?
First put to crontab entry for automation purposes. Secondly this is request by application team to at least flash or refresh the server and kill those runaway process, (even do we have script to kill those runaway, this is kind of a policy and agreed for preventive and system integrity check).
I totally agree with you that reboot must be interactively to see and check whats going on and make it sure that system is up and running, but due to lots of server we need to maintain we need to do this in automated process.
Thanks for your comment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 08:36 PM
тАО09-28-2004 08:36 PM
Re: How to setup cron to run on second sunday of the month?
You should put:
0 8 8-14 2,4,6,8,10,12 0 /etc/shutdown -r -y now # Rebooting only second Sunday
I used Ermin's trick.
Regards,
Borislav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 09:00 PM
тАО09-28-2004 09:00 PM
Re: How to setup cron to run on second sunday of the month?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-28-2004 09:03 PM
тАО09-28-2004 09:03 PM
Re: How to setup cron to run on second sunday of the month?
0 8 7-15 * 0 /etc/shutdown -r -y now
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2004 12:10 AM
тАО09-29-2004 12:10 AM
Re: How to setup cron to run on second sunday of the month?
0 8 8-14 2,4,6,8,10,12 0 /etc/shutdown -r -y 0
regards
SK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2004 01:59 AM
тАО09-29-2004 01:59 AM
Re: How to setup cron to run on second sunday of the month?
With this in the script who cares how the cron is setup.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2004 02:00 AM
тАО09-29-2004 02:00 AM
SolutionPlease see the question I posted for a similar requirement and the answers to it, below
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=593710
Also from the man pages of crontab,
------------------------------------------
ote that the
specification of days can be made in two fields: monthday and weekday.
If both are specified in an entry, they are cumulative. For example,
0 0 1,15 * 1 command
runs command at midnight on the first and fifteenth of each month, as
well as every Monday.
-------------------------------------------
In simple terms, you cannot achieve this directly through cron. You may have to write a script for achieving your requirement.
Also consider using caldj.sh. You can search with the same word in this forum and will find lots of references.
All the best.
With regards,
Mohan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2004 02:09 PM
тАО09-29-2004 02:09 PM
Re: How to setup cron to run on second sunday of the month?
Thanks you guys for all your help, it was great help and to have those ideas and confirmation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 09:51 AM
тАО09-30-2004 09:51 AM
Re: How to setup cron to run on second sunday of the month?
0 8 8-14 * * /usr/local/rebootsundays.sh
Here is a tested script to do the job:
#!/bin/sh
#
# rebootsundays.sh
#
# If today is Sunday, reboot!
#
DAY=`date +%w`
#
# This script should be run by root:
if [ x`id | grep root | awk '{print $1}'` = "x" ]; then
echo "Root privileges are required to run `basename $0`"
exit
fi
# If it is Sunday, reboot the system.
if [ "$DAY" -eq 0 ];then
cd /
/usr/sbin/shutdown -r -y 0
else
echo "I only reboot on Sunday."
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-30-2004 10:11 AM
тАО09-30-2004 10:11 AM
Re: How to setup cron to run on second sunday of the month?
#!/usr/bin/sh
export PATH=${PATH}:/usr/local/bin
if [[ $(caljd.sh -N) -eq 2 ]]
then
echo "Second Sunday; do your thing"
else
exit 0
fi
Now if the question is to do something every other Sunday then, again, your cron job executes every Sunday;
#!/usr/bin/sh
export PATH=${PATH}:/usr/local/bin
WK=$(( ($(caljd.sh) + 1 ) / 7 ))
if [[ $((${WK} % 2)) -eq 0 ]]
then
echo "Do your thing"
else
exit 0
fi
You may need to reverse the conditions depending upon which week you want to start on; the $(caljd.sh) + 1 is used to start the week on Sunday.
Invoke as caljd.sh -u for full usage and examples.