views:

41

answers:

2

This function take hugh amount of time to calculate the status of a process, beacuse every time it has to ssh into the machine and find the status of a process.

I only have four machines and around 50+ process to monitor and the details are mentioned into configDaemonDetails.txt

like:

abc@sn123|Daemon_1|processname_1
abc@sn123|Daemon_2|processname_2
efg@sn321|Daemon_3|processname_3 

How to reduce the time with doing ssh once into a machine and finding all its process informations as defined in the txt file. ?

CheckProcessStatus ()
{
         echo "              ***** Checking Process Status ***** "
         echo "========================================================="
         IFS='|'
         cat configDaemonDetails.txt | grep -v "^#" | while read MachineDetail Daemon ProcessName
         do

                Status=`ssh -f -T ${MachineDetail} ps -ef | egrep -v "grep|less|vi|more" | grep "$ProcessName"`
                RunTime=`echo "$Status" | sed -e 1'p' -e '1,$d' | awk '{print $5" "$6}'`
                if [ -z "$Status" ]
                        then
                                echo "The Process is DOWN $Daemon | $ProcessName "
                        else
                                echo "The Process $Daemon | $ProcessName is up since  $RunTime"
                fi

         done

         echo "-----------------------------------------------------"

}

Thanks :)

+2  A: 

Can't you just fetch the entire ps -ef output at once, and then parse it appropriately? I suspect that is what you are asking, and maybe all you want is an example of how to do that? If that is the case, say so and I'll flesh out an example.

MJB
how do I provide all process name from the file to ps -ef ?
Joice
Don't provide them all at once. Get the ENTIRE output from ps -ef on the remote machine, and process it all at your local machine. Or if that is too much, you can do a ps -uf {username} if all the procs are running under the same account.
MJB
ok ok I got it .. thanks a lot
Joice
Joice
A: 

SSH is a bit over kill for getting status of a process, I'd suggest using SNMP instead.

e.g, you can get a process list like this:

snmpwalk -v2c -cPASSWORD HOST 1.3.6.1.2.1.25.4.2.1

Take a look at this Nagios plugin that does process checks, and look in the code for the actual SNMP OIDs.

miedwar
I will surely try that ... thanks
Joice