linux shell 关键字查找,返回OK 否则NO

本人在XXX银行在linux运维,根据工作的需要写了简单的脚本;需求是在一台linux服务器上,为确保磁盘可用率在正常范围之内,通指定脚本将信息打印在/tmp的日志中,此脚本省略。结合外部厂商的监控系统,写下此脚本查找磁盘使用率日志的关键字,配置在监控系统,每五分钟执行一次,返回OK,磁盘使用率正常,否则反之。

#!/bin/bash
#Date:2017-01-22
#Editor:qiuqingyun
#Email:[email protected]
#find character word by cmd:while wc if expr
#if print OK word is not change;but print ERROR it is that anyone has changed
lines=`wc -l /opt/ETL.txt|awk '{print $1}'`
startLine=4
while [ $lines -ge $startLine ]
do
        WordF=`cat /opt/ETL.txt|awk 'NR=='$lines'{print $7}'`
        WordS=`cat /opt/ETL.txt|awk 'NR=='$lines'{print $8}'`
        if [ "$WordF" == "ready" ]&&[ "$WordS" == "up" ];then
                lines=`expr $lines - 1`
                if [ $lines -eq 4 ];then
                        echo "OK"
                fi
                continue
        else
                echo "ERROR"
                break
        fi
done

linux shell 关键字查找,返回OK 否则NO_第1张图片

你可能感兴趣的:(linux-shell)