首页 > 代码库 > shell监控脚本,不考虑多用户情况

shell监控脚本,不考虑多用户情况

#!/bin/bash

CheckProcess()   
{   
        if [ "$1" = "" ];   
        then   
                return 1   
        fi   
  
    PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l`   
    if [ $PROCESS_NUM -eq 1 ];   
    then   
        return 0   
    else  
        return 1   
    fi       
}    
  
while [ 1 ] ; do  
#输入进程名 
echo "$1";
echo "$2";
echo "$3";
   CheckProcess "$1"  
    CheckQQ_RET=$?   
    if [ $CheckQQ_RET -eq 1 ];   
    then   
    # killall -9 a.out   
    # exec ./a.out &
 #java -cp /home/hadoop/hivestudy/task2-2.0.jar com.my.task2.FileMoniter /home/hadoop/hivestudy/task2Data .success 10 /home/hadoop/hivestudy/task2Data/task2.datacnf   
#  要执行的进程名
   $2 
  fi   
#多久执行一次
    sleep $3   
done  

 

shell监控脚本,不考虑多用户情况