Nagios无法搜索日志文件

时间:2013-12-07 17:10:55

标签: linux bash shell nagios

我已经为nagios编写了一个简单的Shell脚本。在脚本中我想要拖尾一个特定的文件,然后用特定的单词格式化它并用我知道的单词来表示如果找到了所需的单词,那么它显示为ok,否则就是关键。该插件似乎只在我正在执行的日志文件位于/ usr / local / nagios / libexec目录内而不是其他任何地方时才起作用。但我希望nagios搜索整个系统,然后找到所需的日志文件和然后执行所需的操作。 请帮忙

check_status()
{

    #!/bin/sh
    word1="flag"                      
    word2="STDOUT"          #wirte the word that you want to 
    find                            
    word3="CALLSTART"           #wirte the word that you want to find 
    word4="Queryyyyselect"
    word5="mobilenumber"
    word6="HLBSA"
    word7="HFA"
    word8="SVA"
    word9="SCA"
    word10="SLBSA"
    a=`timeout 2 tail -f "/usr/local/nagios/libexec/server.log"`

    for word in $word{1,2,3,4,5,6,7,8,9};
    do
        w1=`echo "$a"|egrep -wo "$word"`
        n1=`echo "$w1" | wc -w`
        if [ "$n1" -eq "0" ]; then
            echo "critical: $word not found"
            status=2
        elif [ "$n1" -gt "0" ]; then 
            echo "OK: $word found"
            Status=0
        fi
    done

    return $status
}

check_status

0 个答案:

没有答案
相关问题