Operating System - HP-UX
1850944 Members
2322 Online
104056 Solutions
New Discussion

Re: Creating a crontab to server reboot

 
SOLVED
Go to solution
Jollyjet
Valued Contributor

Creating a crontab to server reboot

Hi All,

I want to reboot a server on first monday of every month any one can help me in this.
9 REPLIES 9
Sunny Jaisinghani
Trusted Contributor
Solution

Re: Creating a crontab to server reboot

Hi,

Refer to the below thread. same issue is discussed in it. the only difference is it is sunday instead of monday :)

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1096366
Steven E. Protter
Exalted Contributor

Re: Creating a crontab to server reboot

Shalom,

cron can't do it by itself.

You need to run a script every monday and use one of these two scripts to determine if its the first monday and therefore to boot.


http://hpux.ws/merijn/caljd-2.25.sh
http://hpux.ws/merijn/caljd-2.2.pl

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
PC_7
Frequent Advisor

Re: Creating a crontab to server reboot

Maybe the following script will help you:

---------------------
#!/sbin/sh

DAYOFWEEK=`/usr/bin/date +%u`
DATE=`/usr/bin/date +%d`
if [ ${DAYOFWEEK} -eq "1" ] && [ ${DATE} -lt '8' ]
then
echo "rebooting server"
/usr/bin/cd /
/usr/sbin/reboot
fi
---------------------

What it will do:
-> find out if the day is Monday and date is less than 8 (ie first Monday)
-> if yes, cd to root and perform reboot


Cheers,
Pau Cen
A. Clay Stephenson
Acclaimed Contributor

Re: Creating a crontab to server reboot

You've gotten the technique to do this but now I'm going to ask why you would want to do this. This is a state of the art dumb thing to do on a UNIX box. Normally the only time a UNIX should come down is for planned maintenace such as applying patches. Most UNIX boxes run for months between reboots. If you are doing this because you have application problems such as memory leaks then you are fixing the symptoms rather than fixing the problems themselves. Moreover, your cron job might just kill a critical task that has been running for hours if not days. When shutdowns are needed, it makes much more sense to manually initiate them so that it can be done safely rather than using some automated approach.
If it ain't broke, I can fix that.
Pete Randall
Outstanding Contributor

Re: Creating a crontab to server reboot

First, I 've got to agree with Clay.

Second, a little caution about the script from Pau Cen:

You don't want to use the reboot command. That will cause an immediate halt of the system. What you probably would prefer to do is a graceful shutdown initiated by the shutdown command "/usr/sbin/shutdown" and you probably want to add the "-r" option so it will reboot. So you want "/usr/sbin/shutdown -r".


Pete

Pete
Yogeeraj_1
Honored Contributor

Re: Creating a crontab to server reboot

hi,

Unattended reboots are not found in the Best Practices list of a good system administrator.

Any reason that you consider it important for your environment?

revert
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
PC_7
Frequent Advisor

Re: Creating a crontab to server reboot

> Second, a little caution
> about the script from Pau Cen:
>
> You don't want to use the
> reboot command. That will cause
> an immediate halt of the system.
> What you probably would prefer to
> ...

Pete, I second what you said. I myself won't put reboot in any script on my production machine - I put reboot in the sample script above just because Jollyjet mentioned in the question "...I want to reboot a server...".

I agree with Clay & Yogeeraj as well that unattended reboots are not a good practice (especially on a production system).

The script was provided under an assumption that the user knows what he/she does.
Jollyjet
Valued Contributor

Re: Creating a crontab to server reboot

Hi Thank's for all your support i found the solution. As I am a Administrator I Know Unnessary reboot does not required this is due to some project devolpment.
Jollyjet
Valued Contributor

Re: Creating a crontab to server reboot

Thanks for all your help