skip # and blank line read file

来源:互联网 发布:python监控hp服务器 编辑:程序博客网 时间:2024/06/09 16:34

check hang process in server

file=$1
while read line
do
        echo "line5:$line"
        #skip comments
        if [ "${line%%\#*}" == "" ]
        then
                continue
        fi

        #skip blank
        if [ "${line%%\b*}" == "" ]
        then
                continue
        fi

        server=`echo $line|nawk '{ print $1 }'`
        echo "line20:$server"
        num=`rsh -n $server ps -ef |grep tweet |wc -l`------------------注意此处要用-n,否则rsh会自动读取下一行,造成1.txt读取错误
                if [ $num -ne 1 ]
                then
                        echo  "hang up process:$server"
                fi
done<$file

 

rsh cool0081 ps -fu tweet>1.txt
rsh cool0081 kill -9 1
while read line
do
        echo $line |grep ps
        if [ $? -eq 1 ]
        then
                echo "$?:$line"
        else
                echo "$?:$line"
        fi
        if [ $? -ne 1 ]
        then
               num=`echo $line |nawk '{print $3}'`
               echo $num
               rsh -n cool0081 kill -9 $num
        fi
done <1.txt

0 0