Below script checks whether MStrsvr process is running or not . The issue I'm facing is if i schedule a cron tab to run this script for every 1 hour it will throw email alert every 1hr that "MSTRSvr is running" which i don't want . I want the script to throw alert only when server is stopped/started.
#!/bin/ksh
hos=$(hostname)
curr_Dt=$(date +"%Y-%m-%d %H:%M:%S")
var=$(ps -ef | grep -i '[/]MSTRSvr')
if [ -z "$var" ]
then
echo "ALERT TIME : $curr_Dt" >>wa.txt
echo "SERVER NAME : $hos" >>wa.txt
echo "\n \n" >>wa.txt
echo " MSTRSvr is not running on $hos Please check for possible impact " >>wa.txt
echo "\n \n" >>wa.txt
mail -s "MSTRSvr process ALERT" [email protected] <wa.txt
else
echo "MSTRSvr is running" >>mi.txt
mail -s "MSTRSvr process ALERT" [email protected] <mi.txt
fi
rm wa.txt 2>ni.txt
rm mi.txt 2>ni.txt
elsepart?/tmp/and add a check for the content of that file.