Operating System - HP-UX
1845906 Members
3832 Online
110250 Solutions
New Discussion

Re: Simple script needed quick

 
Angie_1
Regular Advisor

Simple script needed quick

I am fairly new to scripting.

I need something on an HPUX 11.11 box that will do start named up again if it dies.
We are having some problem with it that we need to further research with HP, but because the weekend is coming up, don't want to make any major changes.

So want a simple script to do a SLEEP and to check to see if named is running. If it isn't, then start it.

Someone please help and please make it simple for me too please.

Thanks,
Angie
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: Simple script needed quick

Let's spawn a cron job every 5 minutes or so instead:

0) Install the attached namedchek.sh in /root/bin.

1) as root:
crontab -l > /tmp/rootcrontab
2) vi /tmp/rootcrontab and add this line:
2,7,12,17,22,27,32,37,42,47,52,57 * * * * /root/bin/namedchek.sh
save the file.
3) crontab < /tmp/rootcrontab

By the way, it's a pretty good idea to do the same with inetd as well. This does not mean that you shouldn't patch named or inetd.

If it ain't broke, I can fix that.
Angie_1
Regular Advisor

Re: Simple script needed quick

Thanks for sending that!!!!

Granted you 10 points.

Angie
Sridhar Bhaskarla
Honored Contributor

Re: Simple script needed quick

I can come up quickly with this. Call it named_restart.sh. You can change the variables to fit to your needs. When you touch a file called /tmp/named_restart.kil, the script will exit. You can run it in background with nohup so that it will run even after you exit the shell.

#!/usr/bin/ksh
PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/usr/contrib/bin
PROC="named"
LOG=/tmp/named_restart.log
STAMP=/tmp/named_restart.kill
INTERVAL=5

while [ true ]
do
if [ -f $STAMP ]
then
echo "$(date): $0: $STAMP file present. Exiting" >> $LOG
exit
else
NUM_PROCS=$(UNIX95= ps -fC $PROC|grep -v CMD|wc -l)
if [ $NUM_PROCS -eq 0 ]
then
echo "$(date): $0: named not running. Starting." >> $LOG
/sbin/init.d/named start >> $LOG 2>&1 # replace it with how you start your named
fi
fi
sleep $INTERVAL
done

Make sure you test it couple of times by stopping named and running the script.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Mic V.
Esteemed Contributor

Re: Simple script needed quick

Angie,

Good idea not to change things before the weekend!

/root/bin doesn't exist by default in HP-UX, so you may need to do this:

mkdir -p /root/bin

before you edit the crontab as A. Clay suggested. The mkdir command creates new directories (folders) and the -p option to the command makes both directories (/root and /root/bin) at the same time. Saves typing it twice. :)

By the way, thanks for making use of the points system. Some people, such as A. Clay, spend a lot of time answering questions for free. (Unfortunately, I haven't seen his points actually show up yet, not sure if things are delayed or what...).


Good luck,
Mic
What kind of a name is 'Wolverine'?
Sridhar Bhaskarla
Honored Contributor

Re: Simple script needed quick

Hi (Again),

Just in case if you want to test my script, there is a space between UNIX95= and ps

UNIX95= ps -fC
^

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
R. Allan Hicks
Trusted Contributor

Re: Simple script needed quick

an oldie but a goodie

#!/bin/ksh

while [ 1 -eq 1 ]
do

let myProcs=`grep yourproghere|grep -v grep |wc -l

if myProcs -lt 1 then
restart your proc here
fi

sleep 10

done

"Only he who attempts the absurd is capable of achieving the impossible
Steven E. Protter
Exalted Contributor

Re: Simple script needed quick

Lots of ways to do it, here is my version:

It runs on root cron, i send the output to a mailbox in the Outlook server 2>&1 mailx "Named daemon" someone@juf.org

nameprod=$(ps -ef | grep named | wc -l)

rc=0
if [ $nameprod -ge 1 ]
then
echo "Named is running fine"
else
echo "Cron is attempting BIND restart"
/sbin/init.d/named start
rc=$?
fi

if [ $rc -ne 0 ]
then
# Take action, email Steve's Cell phone
echo "Emailing Steve's Cell phone"
fi

Pretty simple, I'm leavin actual action of the script for you to decide because only you know how urgent it is that named id down.

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