1821868 Members
2987 Online
109638 Solutions
New Discussion юеВ

Re: Cron Reboot Script

 
SOLVED
Go to solution
Ronald Angel
Occasional Advisor

Cron Reboot Script

I have been tasked with having our HP-UX servers rebooted every 28th day at 5:30am. I haven't been able to locate a utility that will convert the date to Julian format. Is this utility available or is there a script out there that will do the job?
18 REPLIES 18
Tomek Gryszkiewicz
Trusted Contributor

Re: Cron Reboot Script

Hi
If you want to run any command every 28th hust add the following line to the crontab:
30 5 28 * * command

-Tomek
Patrick Wallek
Honored Contributor

Re: Cron Reboot Script

Have a look at this thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x9e2631ec5e34d711abdc0090277a778c,00.html

Scroll down to A. Clay Stephensons reply and grab his attached script, caljd.sh. That script is fast becoming the Forums standard for working with dates.
Jeff Schussele
Honored Contributor

Re: Cron Reboot Script

Hi Ron,

Search the forum for caljd.sh or caljd.pl.
This is Clay's excellent date hammer. This will do it for you.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Ronald Angel
Occasional Advisor

Re: Cron Reboot Script

Thank you all for such a quick response. I will give the first one a try and go from there. I'll be back with my results. Thank you all again.
Sridhar Bhaskarla
Honored Contributor

Re: Cron Reboot Script

Hi,

I wonder why you would want to reboot the servers everymonth. You do not need to do it.

If it is insisted by the management (sometimes we can't help) then write a script that will shutdown the application. Something like this.

#!/usr/bin/ksh


command_to_stop_apps
if [ $? = 0 ]
then
/usr/sbin/shutdown -r now
else
echo "Application is not down" |mailx -s "${hostname) not rebooted" your_address
fi

Call this monthly_reboot.sh

Place an entry

30 05 28 * * /wherever/monthly_reboot.sh

into your root's cronjobs.

This will run the script every month on 28th at 5:30 AM.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Jeff Schussele
Honored Contributor

Re: Cron Reboot Script

Hi Ron,

That first response will run the command on the 28th of every month - not every 28 days. Use Clay's script to do it every 28 days. Believe you just need to run caljd.sh -u for usage notes.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
James R. Ferguson
Acclaimed Contributor

Re: Cron Reboot Script

Hi Ron:

If "every 28 days" indeed means every 28th day increment as Jeff suggests, one way to accomodate this is to leverage 'at' with the "next timeunit" specification:

# at -f job-file time [date] [next timeunit|+count timeunit]

Thus, when your script runs, the last thing *it* does is to issue an 'at' request thereby rescheduling itself.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Cron Reboot Script

While I think rebooting every 28 days is state of the art dumb. Here is how to do it with a cron script set to run 0530 everyday.

#Set GOOD_DAY between 0 and 27

GOOD_DAY=7
if [[ $(($(caljd.sh) % 28)) -eq ${GOOD_DAY} ]]
then
echo "Do your thing"
else
exit 0
fi
If it ain't broke, I can fix that.
Ronald Angel
Occasional Advisor

Re: Cron Reboot Script

I'll add additional info that I omitted from the inital question. Management wants the servers rebooted every 28 days starting at a specific date for each server. The first server reboot is set for tomorrow. Management (Windows guy) thinks that they should all be rebooted at least once a month and wants it automated. I intend on using the highly touted caljd.sh script you are all raving about and will pass it to my co-worker. I'm also going to utilize the /sbin/reboot script provided in HP-UX11. I didn't have much luck running the shutdown command via a cron script. Thank you all again.
Jeff Schussele
Honored Contributor

Re: Cron Reboot Script

A Micro$oft guy, huh?
THAT explains a lot.....

Later,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
John Poff
Honored Contributor

Re: Cron Reboot Script

Hi,

Your Windows management guy wants you to reboot every 28 days because that is what he has to do to keep his Windows servers running, right?

Show him this:

1:25pm up 1150 days, 1:41, 0 users, load average: 0.07, 0.07, 0.07

It is the actual uptime from one of our HP-UX servers. It hasn't been down for over three years now.

Next, he'll probably want you to automate the daylight savings time change. We can help you with that one too! ;)

JP
Jeff Schussele
Honored Contributor

Re: Cron Reboot Script

Hey JP,

Anybody ever question the patch level of that server?
What do you tell them - that you're trying to set a record?

Cheers,
Jeff (UPTIME, baby...that's what we're talking about!)
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
John Poff
Honored Contributor

Re: Cron Reboot Script

Jeff,

There are two schools of thought on patching:

1. Patch it regularly.

2. Don't patch anything unless it is broken.

I'm in the first school, but this server is halfway across the country, and as long as it runs fine I don't want to mess with it. Besides, everytime our Windows guys start giving me a hard time here I just e-mail them the latest 'uptime' from that server and ask them, "Got Unix?"

Besides, remember that scene from "Blazing Saddles"?

"Patches? We don't need no steeenking patches!!" :)

JP
Ronald Angel
Occasional Advisor

Re: Cron Reboot Script

THank you all again.... I agree with Clay's statement regarding "state of the art". Where may I download this caljd.sh script?
Jeff Schussele
Honored Contributor

Re: Cron Reboot Script

JP,

Yep, I hear ya.
If I were you though, NEXT time it has to be rebooted, I'd have a replacement drive or two handy - just in case. Definitely, if it has to be power cycled.

Yea, that a funny line. Think it was first heard in an old John Wayne movie - Rio Lobo or Rio Bravo, I think.
"Badges?!?! We don't need no stinking badges!"

One of my favorites is in Three Amigos, I think, where these decrepit bandits are bandying about the term plethora - it's funny as hell.

Cheers,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Patrick Wallek
Honored Contributor

Re: Cron Reboot Script

Ron,

Have a look at my first reply. Go to that thread and then go to A. Clay's response in that thread. The caljd.sh script is attached to his response.
A. Clay Stephenson
Acclaimed Contributor

Re: Cron Reboot Script

Hi Ron:

Here you go, although a search would have pulled up caljd.sh. Version 2.10 is the latest.


If it ain't broke, I can fix that.
Chris Vail
Honored Contributor

Re: Cron Reboot Script

The 'we don't need no stinking badges' is from _Tresure of the Sierra Madre_, 1935 by John Huston--spoken by some bit-part player unmentioned in the credits (this was 1935, afterall). Google, as always, is your friend.

Anyway, I'm with the others that believe that rebooting a Unix server every 28 days (or on any regular basis) is something worthy of a Monty Python skit. This is a stable code base--no memory leaks (well, usually) that require a reset. I've got systems here that I actually forgot they existed because they require so little attention--uptime +400 days. We re-discovered them recently because we moved our data center, and somebody asked "Hey whats this?". The application, of course, was in Cobol, and used a flat file database with ISAM.

Why don't you ask the boss to see how long your system can go without a reboot?


Chris