Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

korn shell script that searches for various processes 1

Status
Not open for further replies.

icu812

MIS
Sep 10, 2001
52
US
Good morning all. I have a korn shell script that I'd like to write that does the following. It searches on one host for the existence of a process called "tnslsnr trn" and then on another box for the existence of a process called "tnslsnr DEV". I've written the following so far but don't know how to cause it to look for one process on the first host and then another process on the second host without going through alot of lines of code.(The test_hostlist file contains the hostnames of the two machines.

#!/bin/ksh
for HOST in `cat /test_hostlist`
do
dsh -w $HOST ps -ef|grep -v grep|grep "tnslsnr trn"
if [ $? -eq 1 ]
then
echo " The tnslsnr trn process on $HOST is down"
else
echo "The tnslsnr trn process on $HOST is up"
fi
done
Can someone please help. Thanks alot.
 
assumption....dsh is a valid command(not familiar with it)

change your test_hostlist to be a 2 field list of:

hostname=processname
(note the use of an character rather than a space as a seperator)

for i in `cat test_hostlist`
do
HOST=`echo $i | cut -d"=" -f1`
PROCESSNAME=`echo $i | cut -d"=" -f2`
dsh -w $HOST ps -ef|grep -v grep|grep "$PROCESSNAME"
if [ $? -eq 1 ]
then
echo " The $PROCESSNAME process on $HOST is down"
else
echo "The $PROCESSNAME process on $HOST is up"
fi
done

this test now can be used now as a generic process check.

hth
stan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top