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 gkittelson 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

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.
 
Looks like you are running Oracle. Consider using the /etc/oratab file. It can help you.

If not, then change your /test_hostlist file as follows:

hostname:trn
hostname:DEV
...and so on

Then, in your script:

#!/bin/ksh
list="[t]nslsnr"
for entry in `cat /test_hostlist`
do
host=`echo "$entry"|cut -f1 -d":"`
tns=`echo "$entry"|cut -f2 -d":"`
object="${list} ${tns}"
dsh -w $host ps -ef|grep "$object" 1>/dev/null 2>&1
if [ $? -eq 1 ]
then
echo " ${object} process on $host is down"
else
echo " ${object} process on $host is up"
fi
done


Try this. You may need to tweak it a bit.

Bill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top