本文介绍了我如何编写shell脚本来检查应用程序的运行状况。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个shell脚本(Health_app.sh)来检查应用程序的运行状况。为此,它从App_Details文件中获取进程的名称并检查pid(是否正在运行)以及是否它没有在日志(字段3)中运行和grep该进程,并将电子邮件发送到App_Details文件中提到的电子邮件ID(字段4)。



App_Details是有以下记录:



process_Name | Process_description | logfile_path | email



abcd |主要程序调用dataready | 1233/456 / log | vikas@yahoo.com



pqrs |第二个过程................ .......... | 1223/456 / log | vikas@yahoo.com



以下是我的剧本的样子:



export App_Details = / home / 123 / sanity / App_Details



read line



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

如果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))}'`

导出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`b尾-10 $ file_name`)

(echo`b尾-10 $ file_name`)>> send.txt

mailx -s请找到您的应用程序OFFLINE服务的提醒vikas@domain.com< send.txt

fi

echo $ PROCID | awk'{printf(% - 20s,$ 0)}'

echo $ procname | awk'{printf(% - 20s,$ 0)}'

echo $ PROCDES | awk'{printf(% - 20s \ nn,$ 0)}'

完成< $ App_Details



现在问题是grep -q对于solaris是非法的,并且它在Solaris服务器中不起作用。

解决方案




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.

解决方案




这篇关于我如何编写shell脚本来检查应用程序的运行状况。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:43
查看更多