[lingh@itmapp3 shell]$ cat count.sh
while true
do 
echo $restartCount
restartCount=`expr $restartCount + 1`
sleep 1
if [ "$restartCount" = "10" ];then 
        restartCount=0 
fi
done
[lingh@itmapp3 shell]$ 
----------------------------------------------------------------
五秒监控一次,根据启动时间不同,最后时间可能在00~04秒之间
[lingh@itmapp3 shell]$ cat count.sh
while true
do 
        echo "restartCount:$restartCount"
        nowTime=`date +%S`
        echo "nowTime:$nowTime"
        #if [ "$nowTime" = "00" -r "$nowTime" = "01" -r "$nowTime" = "02" -r "$nowTime" = "03" -r "$nowTime" = "04" ]; then
        #if [ "$nowTime" = "0\[01234\]" ]; then
        IsIn0To5=`echo $nowTime|grep 0[0-4]|wc -l`】
        echo "IsIn0To5:$IsIn0To5"
        if [ "$IsIn0To5" = "1" ];then
                echo "0004"
               restartCount=0
        fi
        restartCount=`expr $restartCount + 1`
        sleep 5
        if [ $restartCount -gt 5 ]; then 
                echo " restartCount gt 5 "
        fi
done
应用,一定计数打到后自动退出,用于测试一些特殊情况,又防止程序一直跑不停。
[nmtestv3@itmapp3 bin]$ cat linghtest.sh
count=1
while true
do
        echo "111111111"
        sleep 5
        count=`expr $count + 1 `linux shell编程求和
        echo "count:$count"
        if [ $count -gt 5 ]; then
                echo "count >3,exit"
                exit
        fi

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。