自动监控进程并启动的shell脚本

来源:互联网 发布:大学生it就业培训中心 编辑:程序博客网 时间:2024/05/18 21:50

实现过程:每个一秒ps一次进程是否存在,不存在则nohup启动之。


用法:autostart "test 1"


autostart(){        if [ $# -eq 0 ]        then                echo "usage: autostart \"test 1\""                 echo                return        fi        while [ 1 ]        do                ps -ef |grep -w "$1" |grep -w `whoami`|grep -vw grep|grep -vw tail                if [ $? -ne 0 ]                then echo "start process....."                        nohup $1 >/dev/null &                else                echo "runing....."                fi                sleep 1        done}







0 0