用於檢測進程的shell腳本

用於檢測進程的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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章