天天看点

系统管理 系统状态 shell

以下是用while循环写的一个监测nginx服务的例子。

#!/bin/bash

while [ 1 ]

        do

TAG=`ps -ef |grep -v "grep" |grep nginx`

if [ "$TAG" = "" ];then

/usr/local/nginx/sbin/nginx

else

    TAGG=`echo "$TAG"|wc -l`

    if [ "$TAGG" != 4 ];then

    fi

fi

        sleep 1

done