Unix上进程监控脚本
上一篇 / 下一篇 2009-02-09 22:50:03 / 个人分类:Shell 编程
- 文件版本: V1.0
- 开发商: 本站原创
- 文件来源: 本地
- 界面语言: 简体中文
- 授权方式: 免费
- 运行平台: Win9X/Win2000/WinXP
0M|o
md x051Testing软件测试网*y-a!M\0X/V^2~
#!/bin/bash51Testing软件测试网2q2FN,p!Mug
Vq:[
#
KDLo1S3M6G0##########################################################################################
6q[fv\o4QI K0#51Testing软件测试网 ?aYKm^&^J
# name: dog.sh
Q*D#z_(WX[0# brief: monitor the running program.
!F5CC2Sxi!A0# author: Robbinson
T7}LY:O&aX8s_*zR0# date: 2007-09-2451Testing软件测试网9b*gENm)t/t&V1m
# args:51Testing软件测试网#cj1QI
q#C9`
#
]?9^`K
l0##########################################################################################
9Xf~2[$V(@0E0##########################################################################################51Testing软件测试网,ueB+z]7WS
#51Testing软件测试网sbiL?`K/W
# brief: If the program is running51Testing软件测试网Ytl {_9E/CGN
# pram: $1: a command line from the dog.cnf
%`?K'b,kY;X6Z0# retval: 0--exit, 1--running, 2--killed
YEz%Q(@0#51Testing软件测试网
hT)uH}Q
##########################################################################################51Testing软件测试网;X'v:v Q};b
is_running( )51Testing软件测试网 z;KB`6@vv4}qFR/m{
{51Testing软件测试网lA6D K;f3L:F
exe_file=`echo $line | awk '{print $1}'`51Testing软件测试网
?*S*B"E Ws%v^ Y
7OTe"e4EE8v6Tr0 pid=`ps -e -o pid,args | grep $exe_file | grep -v grep | awk '{print $1}'`
$B
tj@!Sr0JTF+h0 if [ "$pid" != "" ]
2ACl Lacm;Q0 then
#M.j$a
OC)e'p\5M0 if [ "$is_kill" -eq "1" ]51Testing软件测试网O&[.p.wg
then51Testing软件测试网;^1i(gh-NW
kill -9 $pid51Testing软件测试网/d{&_xC(C1\1`
return 251Testing软件测试网;rM7ld[6\X
else51Testing软件测试网 N$x.a5F2H
g
return 1
qRLR0^Q'e0 fi
4D-Hra5I/T+D*j0 fi
{$c@0W4no.n#f:E0 return 0
S^[9O!h0}
ky[ Z_0MSO0##########################################################################################51Testing软件测试网'd,AeYSd
#
:Qrf)iw ^G0# brief: starup the program
LjH8dO
@0# pram: $1: a command line from the dog.cnf51Testing软件测试网(U
Jw"h#z-MY5]
# retval: 0--OK, 1--Fail51Testing软件测试网T-[&AM7GW!T
#51Testing软件测试网?z2o,j6r2~A
p
##########################################################################################51Testing软件测试网_a-R#@2CY^4iq
start_up( )
k1Jpk@o&JI4M0{
0yKP3k#e&O*\}[0 exe_file=`echo $line | awk '{print $1}'`
eCI'F8Ja0 count=`echo $exe_file | awk -F/ '{print NF}'`
OU8g9AU!@0 count=`expr $count - 1`51Testing软件测试网;O
o2p8Mv$lG
path=`echo $exe_file | cut -d/ -f1-$count`51Testing软件测试网,@]5`7_S
b$L
cd $path51Testing软件测试网`^"v1fLK
$line51Testing软件测试网"R1?:P'|Ar
}51Testing软件测试网W/CExQFx
?6F8\+x4A
VL}@.|7B0##########################################################################################51Testing软件测试网.\!PGb'xTD@
#
Z nFM'm$D"]j0# brief: Guard all process from the dog.cnf51Testing软件测试网H.ZN&_#f+u&T6\
#
U"D&^
cxe0u-Y'W0##########################################################################################51Testing软件测试网hPt(]U5}#\s
guard_process( )
'yDy7[6o5I
s0{
#~6VTLkO(X0 is_kill=051Testing软件测试网sw%q3Va(Z
k
RU.E|V-I0 while read line51Testing软件测试网(D*c4pK6}$cR^n M
do51Testing软件测试网[%Y a'jUHu
[iPo
case $line in51Testing软件测试网 {9n P+J*s/iTN
\#*)51Testing软件测试网9@5l'J9i.YhO$jXU
;; # ignore any hash signs51Testing软件测试网
[i esg0w*Y)A
*)
PLm9c { b.}p4k0 is_running $line, $is_kill
R2_M] G4_yIH0 if [ $? = 0 ]51Testing软件测试网f_W:Sd2T%AVl
then51Testing软件测试网b,m{pD:a Z
start_up $line
uM(sA+P/i0 fi51Testing软件测试网ye
P9_W/gF/HR
;;51Testing软件测试网^)U:@K%V
esac
U*yS3y??6VD:G/n0 done < $dog_cnf
9oCc _p"YZ7`#i2gJ0}
*c6qf i1EKY~051Testing软件测试网3glJ;SZ;lr
##########################################################################################51Testing软件测试网)D;YaMhi0X~
#51Testing软件测试网-yzgp.DFi+f
# brief: List all process from the dog.cnf51Testing软件测试网 CMYE f@hs
#
wQ8DQ(_7bg0##########################################################################################
Lv2b-Q2I"R0list_process( )51Testing软件测试网1GJ^(Q*R
?6C
{51Testing软件测试网'pa&To:`Y)t'MPCl5K
index=051Testing软件测试网$lr n\&L1n8]
Q&K
is_kill=0
8q!^ OU \hb0 echo "index status line"51Testing软件测试网i h*Cl/agl$g
echo "-------------------------------------------------------------------------------"51Testing软件测试网aKL7E&X8B
fc
-zt;OR(s G0N0 while read line51Testing软件测试网K)be8Lki
do51Testing软件测试网,tdhE/y6[?
case $line in
-I$z`H6rOh
\#E[T0 \#*)51Testing软件测试网7y_C(by
;; # ignore any hash signs51Testing软件测试网o6pt1p O-cp
*)
BoRT1z0 st_des="run"51Testing软件测试网D)eRr9|
is_running $line, $is_kill
8XV6lk c4x@c0 if [ $? = 0 ]51Testing软件测试网9N_}I]WH
H6W{b*a
then