昨晚上临下班的时候项目经理说在主机上查询进程一个个找起来太繁琐了,让我去写一个shell脚本,可以固定查询几个主机进程。
我是研发部的实习生,我从来没接触过shell,只是简单的使用linux命令。
然后我就去看了下shell文档,我发现shell是真的很简单,逻辑思维和c基本一致。
下面源码奉上
#! /bin/bash
a="GNERR_A"
b="NG_IGNS"
c="TIMER_C"
d="NG_IBSB"
e="NG_CLPAT"
f="NG_DSMPA"
ps aux|grep -q "^$a"
case $? in
0)
echo " $a is running"
;;
*)
echo "$a is not running"
esac
ps aux|grep -q "^$b"
case $? in
0)
echo " $b is running"
;;
*)
echo "$b is not running"
esac
ps aux|grep -q "^$c"
case $? in
0)
echo " $c is running"
;;
*)
echo "$c is not running"
esac
ps aux|grep -q "^$d"
case $? in
0)
echo " $d is running"
;;
*)
echo "$d is not running"
esac
ps aux|grep -q "^$e"
case $? in
0)
echo " $e is running"
;;
*)
echo "$e is not running"
esac
ps aux|grep -q "^$f"
case $? in
0)
echo " $f is running"
;;
*)
echo "$f is not running"
esac