Script to check running processes on remote server.

Hi,

I am trying to write a script, which queries a db to get the names of processes, stores it in a file and then checks if that process is running on a remote server. However I am not getting it right, could anyone help me out.

#!/bin/sh
echo "select Address from Device where Cust = '3-136VFF' and State = -2" | mysql Pen | grep -v Address > ./ge1
cat ./ge1 | \
while read line
do
a = ""
a = $(`rsh ontrack 'ps -ef | grep -v grep | grep $line' | awk '{print $2}'`)
if[$a -eq ""]; then
echo "process for $line not running";
done

Thanks,
Amit

i dont know. others may disagree with this but to me its always a very good idea to specify the path to any file/script that your script is going to be running or working on. cat ./gel can cause potential unnecessary headaches.

cat /path/to/file/gel is always better than cat ./gel

Thanks for you advise....I will be implementing that in the final script.....I am still testing it...

trying a different approach...but still some errors in it....any help will be highly appreciated....

#!/bin/ksh
for I in `echo "select Address from Dev where Cust = '3-136VFF' and State = -2" | mysql Pen`; do
ip=`rsh ont 'ps -ef | awk '{print $9}' | grep -x $I`
if [ $I -ne $ip ]; then
echo "process for Ip $I not running" >> /tmp/getmon
fi
cat /tmp/getmon
done

That's not enough information (at least for me). Could you post an example of:
"`echo "select Address from Dev where Cust = '3-136VFF' and State = -2" | mysql Pen`"
output?
Anyway, change your if and use:

if [[ "$I" !=  "$ip"]]; then

If you are comparing strings.

And take into account that you are assuming that both "select" and "rsh" are working and returning valid data...

Regards.

Hi,

The ip variable is not getting the values. $I has the values
ip=`rsh ont "ps -ef | awk '{print $9}' | grep -x $I"`
is there any prob with the quotes ?

Thanks,
Amit