I have written one shell script (Health_app.sh) which checks the health of the application. And for that it takes the name of the processes from App_Details file and checks for PID (whether it is running or not) and if it is not running and grep for that process in logs (field 3) and send email to the email id mentioned in the App_Details file (field 4).
App_Details is having records like:
process_Name|Process_description|logfile_path|email
abcd|main proceess to invoke the dataready|/123/456/log|[email protected]
pqrs|2nd process..........................|/123/456/log|[email protected]
Here is how my script looks like:
export App_Details=/home/123/sanity/App_Details
while read line
do
export procname=$(echo $line | cut -d " " -f1)
export PROCDES=$(echo $line | cut -d " " -f2)
#if ps -ef |grep [`echo $procname|awk '{print substr($0,1,1)}'`] [`echo $procname|awk '{print substr($0,2,length($0))}'`]> /dev/null
if ps -ef |grep -q [`echo $procname|awk '{print substr($0,1,1)}'`] `echo $procname|awk '{print substr($0,2,length($0))}'`
then
export part1=[`echo $procname|awk '{print substr($0,1,1)}'`]
export part2=`echo $procname|awk '{print substr($0,2,length($0))}'`
export PROCID=`ps -ef |grep $part1$part2|awk -F ' ' '{print $2}'`
else
export PROCID="OFFLINE"
trace_path=$(echo $line | cut -d " " -f3)
export mail=$(echo $line | cut -d " " -f4)
file_name=`ls -rt $trace_path/$procname*.trc 2>/dev/null | tail -1`
#export PROCDES=$(echo `tail -10 $file_name`)
(echo `tail -10 $file_name`) >> send.txt
mailx -s "Please find the alerts for your application OFFLINE services" [email protected] < send.txt
fi
echo $PROCID|awk '{ printf("%-20s", $0)}'
echo $procname|awk '{ printf("%-20s", $0)}'
echo $PROCDES|awk '{ printf("%-20s\n", $0)}'
done<$App_Details
Now the issue is that grep -q
is illegal for solaris and it is not working in solaris server.