Check all needed processes of a machine via RMA for Unix

If you have information, script, utility, or idea that can be useful for HostMonitor community, you welcome to share information in this forum.
Post Reply
ataudte
Posts: 28
Joined: Wed Apr 23, 2008 3:40 am
Location: FFM, Germany

Check all needed processes of a machine via RMA for Unix

Post by ataudte »

Hello everybody,

I was asked by Alex (KS-Soft) to publish my shell script to check all relevant processes of an Unix machine tested by RMA for Unix.

I will give you a little explanation in the problem I had. I have to know, whether a process with its specific parameters is running, e.g.

Code: Select all

nsrlcpd -s server4711 -N 1 -n 1
nsrmmd -n 2 -s server4711
With the "Process" test of HostMonitor, I just get "nsrlcpd" and "nsrmmd", but there are processes with multiple instances. They differ in their parameters.

My solution:
At the RMA a config file is placed. In this file stands all the processes with their parameters I want to monitor (see code above). I insert the following script in the "Script Manager". The committed parameter is the path to the config file at the machine.

Params in test properties:

Code: Select all

/opt/hostmonitor/cfg/chk_proc/proc.cfg
The script in the "Script Manager":

Code: Select all

#!/usr/bin/bash
#---Error Treatment---
if [ $# -eq 0 ]; then
   echo "ScriptRes:Bad:Missing Parameters!"
   exit
else
   #---set config-file---
   if [ ! -f "$1" ]; then
      echo "ScriptRes:Bad:Config File ($1) does not exist"
      exit
   else
      cfg_file=$1
   fi
fi
#
#######################
# Check Proc Function #
#######################
check_proc() {
 if [ -z $1 ]; then
    echo "ScriptRes:Bad:No Program specified"
    exit
  fi
  ps -ef | grep -v grep | grep "$*" > /dev/null
  if [ $? -eq 0 ]; then
    return 0
  else
    return 1
  fi
}
#
#################
# Main Funktion #
#################
main_prog() {
  reply=""
  while read line; do
    proc=`echo $line`
    check_proc $proc
    if [ $? -ne 0 ]; then
      reply="$reply \"$proc\""
    fi
  done < $cfg_file
  if [ "$reply" != "" ]; then
    echo "ScriptRes:Bad:Process(es)$reply not running"
  else
    echo "ScriptRes:Ok:All processes active"
  fi
}
#
#
#######
# Run #
#######
main_prog
#-------------------------------------------------------------------------------
The Reply, if process(es), which are listed in the config file aren't running (e.g.):

Code: Select all

Process(es) "nsrlcpd -s server4711 -N 1 -n 1" "nsrmmd -n 2 -s server4711" not running
Now I can use the reply of the test to inform the admin of the Unix machines, which processes aren't runnig at the respective server.

Regards,
ataudte
Post Reply