用於檢測進程的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="\t" '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]
擷取當前記憶體狀態的shell指令碼2009-11-17 15:54
#!/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