Dear all,
I have written a script which is designed to read a file containing a list of running processes and then compare this list with a list of similar processes defined within an array. If and only if there is a process that exists within the array and NOT in the file does a flag get written to disk. I have written the bulk of the code but I am not sure it is working as planned. I would appreciate it if someone would look over the script and provide feedback on it's operation. I will continue to debug it.
Thanks
Alf
Script as follows ................
# START - Set the environment variables
grep_binary="/bin/grep"
awk_binary="/bin/awk"
ovstatus_binary="/opt/OV/bin/ovstatus -c"
output_file="ovstatus"
output_dir="/tmp/"
create_dir="/bin/mkdir"
delete_binary="/bin/rm"
listfilecontents="/bin/cat"
createfile="/bin/touch"
processname=""
# END - Set the environment variables
# Check for the existence of the /tmp directory and create if it is not there.
if [ ! -d $output_dir ] ; then
$create_dir $output_dir
fi
# Create the process output file
#$ovstatus_binary | $grep_binary -v Name | $grep_binary -v NOT_RUNNING | $awk_binary '{print $1}' > $output_dir$output_file
# determine the number of processes to check for
index=0
for index_counter in `cat /tmp/ovstatus`
do
let index=index+1
done
echo $index
# Create the running process arrray
#target[0]="OVsPMD ovsessionmgr ovtrapd ovactiond ovalarmsrv pmd genannosrvr httpd ovrequested ovdbcheck"
target[0]="OVsPMD ovsessionmgr ovtrapd"
counter=0
matched=0
for target in ${target[*]} # List of processes that should be running
do
let counter=counter+1
for readline_process in `$listfilecontents $output_dir$output_file` # determine what processes are running
do
matched=0
if [ ${target[]} = $readline_process ] ; then
processname=${target[]}
processexists=0
if [ -f $output_dir$processname ] ; then
$delete_binary $output_dir$processname
# then call the ovevent clear alarm setup. To be defined.
fi
# let counter=counter+1
matched=1
echo $readline_process,${target[]}," Counter=",$counter," matched =",$matched," processexists=",$processexists
else
# let counter=counter+1
processname=${target[]}
processexists=1
echo $readline_process,${target[]}," Counter=",$counter," matched =",$matched," processexists=",$processexists
if [ $processexists = 1 ] ; then
if [ $matched = 0 ] ; then
echo $processname," not matched here!!"," counter=",$counter
if [ $counter > $index ] ; then
$createfile $output_dir$processname
echo $processname," file written to disk"
fi
fi
fi
# then call the ovevent raised alarm setup. To defined
fi
# let counter=counter+1
done # Inner for loop
done # outer for loop
I have written a script which is designed to read a file containing a list of running processes and then compare this list with a list of similar processes defined within an array. If and only if there is a process that exists within the array and NOT in the file does a flag get written to disk. I have written the bulk of the code but I am not sure it is working as planned. I would appreciate it if someone would look over the script and provide feedback on it's operation. I will continue to debug it.
Thanks
Alf
Script as follows ................
# START - Set the environment variables
grep_binary="/bin/grep"
awk_binary="/bin/awk"
ovstatus_binary="/opt/OV/bin/ovstatus -c"
output_file="ovstatus"
output_dir="/tmp/"
create_dir="/bin/mkdir"
delete_binary="/bin/rm"
listfilecontents="/bin/cat"
createfile="/bin/touch"
processname=""
# END - Set the environment variables
# Check for the existence of the /tmp directory and create if it is not there.
if [ ! -d $output_dir ] ; then
$create_dir $output_dir
fi
# Create the process output file
#$ovstatus_binary | $grep_binary -v Name | $grep_binary -v NOT_RUNNING | $awk_binary '{print $1}' > $output_dir$output_file
# determine the number of processes to check for
index=0
for index_counter in `cat /tmp/ovstatus`
do
let index=index+1
done
echo $index
# Create the running process arrray
#target[0]="OVsPMD ovsessionmgr ovtrapd ovactiond ovalarmsrv pmd genannosrvr httpd ovrequested ovdbcheck"
target[0]="OVsPMD ovsessionmgr ovtrapd"
counter=0
matched=0
for target in ${target[*]} # List of processes that should be running
do
let counter=counter+1
for readline_process in `$listfilecontents $output_dir$output_file` # determine what processes are running
do
matched=0
if [ ${target[]} = $readline_process ] ; then
processname=${target[]}
processexists=0
if [ -f $output_dir$processname ] ; then
$delete_binary $output_dir$processname
# then call the ovevent clear alarm setup. To be defined.
fi
# let counter=counter+1
matched=1
echo $readline_process,${target[]}," Counter=",$counter," matched =",$matched," processexists=",$processexists
else
# let counter=counter+1
processname=${target[]}
processexists=1
echo $readline_process,${target[]}," Counter=",$counter," matched =",$matched," processexists=",$processexists
if [ $processexists = 1 ] ; then
if [ $matched = 0 ] ; then
echo $processname," not matched here!!"," counter=",$counter
if [ $counter > $index ] ; then
$createfile $output_dir$processname
echo $processname," file written to disk"
fi
fi
fi
# then call the ovevent raised alarm setup. To defined
fi
# let counter=counter+1
done # Inner for loop
done # outer for loop