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
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
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
#-------------------------------------------------------------------------------
Code: Select all
Process(es) "nsrlcpd -s server4711 -N 1 -n 1" "nsrmmd -n 2 -s server4711" not running
Regards,
ataudte