用于检测进程的shell脚本
2010-07-07 10:38:08| 分类: Centos |字号 订阅
脚本一:
#!/bin/sh
program=XXXX #进程名
sn=`ps -ef | grep $program | grep -v grep |awk '{print $2}'` #获得进程端口号
if [ "${sn}" = "" ] #如果为空,表示进程未启动
then
nohup /home/oracle/XXXX & #后台启动进程
echo start ok !
else
echo running
fi
脚本二:
#!/bin/sh
ps -ef |grep ./FileServer > /dev/null 2>&1 #检测进程写入/dev/null
if [ $? -eq 0 ] #0为正常
then
echo logprocess run ok!
else
nohup /home/oracle/XXXX &
echo start ok !
fi
脚本三:
#!/bin/sh
count=`ps -fe |grep "a.out" | grep -v "grep" | wc -l`
if [ $count -lt 1 ]; then
/root/sh/restart.sh
脚本四:
PNAME="authd"
PATHNAME=/root/cauthd/build/
LENGTH=`ps -ef|grep "$PNAME"|grep -v grep|cut -b 49-200|wc -c `
if test $LENGTH -eq 0
then
cd $PATHNAME
nohup $PNAME >/dev/null
脚本五:
#! /bin/bash
echo "请输入进程名:"
read process
echo "你要查找的进程是 $process ,正在查找..."
ps > text1
grep "$process" text1
declare -i a=$?
if [ $a -eq 0 ]
then
echo "该进程存在"
else
echo "该进程不存在"
fi
rm text1
检测进程 cpu mem
[code]
[root@test ~]# ps aux |awk -v OFS=" " 'BEGIN{print "httpd"}/%MEM|httpd/{print $3,$4}'
httpd
%CPU %MEM
0.0 1.5
0.0 1.5
0.0 1.5
0.0 1.5
0.0 1.5
0.0 1.5
0.0 0.1
[/code]
#!/bin/sh
while true
do
echo `free | awk '{print $3}'` | awk '{print $2}' >a
str=`cat a`
echo $str
echo `free | awk '{print $2}'` | awk '{print $2}' >b
tot=`cat b`
echo $tot
#rc=`expr $str / $tot`
rate=`echo "scale=2;$str/$tot"|bc`
echo $rate
echo "-------"
sleep 1
done