Click here to Skip to main content
15,914,357 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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 form 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|vikas@yahoo.com

pqrs|2nd process..........................|/123/456/log|vikas@yahoo.com

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" vikas@domain.com < 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.
Posted
Comments
Richard MacCutchan 9-Jun-15 9:59am    
So remove the q option, or find an alternative that does work in Solaris.
Sergey Alexandrovich Kryukov 9-Jun-15 10:51am    
Sorry, it makes no sense at all.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900