ataudte
Joined: 23 Apr 2008 Posts: 28 Location: FFM, Germany
|
Posted: Thu Aug 28, 2008 12:07 am Post subject: Check all needed processes of a machine via RMA for Unix |
|
|
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: |
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: | /opt/hostmonitor/cfg/chk_proc/proc.cfg |
The script in the "Script Manager":
Code: |
#!/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: | 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 |
|