本文介绍了Nagios的插件来检查文件x分钟内创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个bash脚本转换为Nagios的插件

I'm trying to convert a bash script to nagios plugin

该脚本将运行一个find命令,看看文件x分钟内创建的:

The script will run a find command to see if files are created within x minutes:

#!/bin/bash
#
#Check NVR 


newfiles=$(find /srv/unifi-video/videos/* -name '*.ts' -mmin -10 | wc -l)

if [[ $newfiles -eq 0 ]] ; then
    echo "!!!WARNING!!! The NVR has System stopped recording."
fi

我试图把该脚本转换为Nagios的插件在这里:

I tried to convert that script to a Nagios plugin here:

#!/bin/bash
#
#Check NVR
#http://www.netchester.com
#Check if NVR System is recording correctly
newfiles=$(find /srv/unifi-video/videos/* -name '*.ts' -mmin -10 | wc -l)
case $mewfiles in
if [[$newfiles -ne 0]]
then
echo "!!!OK!!! NVR is recording."
exit 0
fi
if [[$newfiles -eq 0]]
then
echo "!!!WARNING!!! NVR is not recording."
exit 1
fi

不过,我不断收到一条错误消息,我每次运行时间:

But I keep getting an error message each time I run it:

./check_nvr.sh: line 9: syntax error near unexpected token `[[$newfiles'
./check_nvr.sh: line 9: `if [[$newfiles -ne 0]]'

我不知道我怎么能解决这个问题。我倒是AP preciate任何指导!

I'm not sure how I can resolve this. I'd appreciate any guidance!

编辑:

我改变了脚本:

#!/bin/bash
#
#Check NVR
#http://www.netchester.com
#Youssef Karami
#Check if NVR System is recording correctly
newfiles=$(find /srv/unifi-video/videos/ -name '*.ts' -mmin -10 | wc -l)
case $newfiles in
[1]*)
echo "OK - $newfiles$ found."
exit 0
;;
[0]*)
echo "WARNING - $newfiles% found."
exit 1
;;
esac

但现在我不后,我跑得到一个输出脚本

But now I don't get an output after I ran the script

推荐答案

@Donald_W

@Donald_W

我把它改变的脚本工作:

I got it to work by changing the script to:

#!/bin/bash
#
#Check NVR
#http://www.netchester.com/scripts_sh/check_nvr
#Youssef Karami
#Check if NVR System is recording correctly
newfiles=$(find /srv/unifi-video/videos/ -name '*.ts' -mmin -10 | wc -l)
case $newfiles in
[1-9]*)
echo "!!!OK!!! - NVR is working properly - $newfiles found."
exit 0
;;
[0]*)
echo "!!!WARNING!!! - NVR is not recording - $newfiles found."
exit 1
;;
esac

不过,我注意到,在Nagios的仪表盘不显示主机未进行记录。我停止了录音只是为了测试,当我跑了剧本我得到的警告消息,但它不会显示在Nagios的一个问题。

But I noticed that in Nagios Dashboard doesn't show that the host is not recording. I stopped the recording just to test and I'm getting the warning message when I ran the script but it doesn't show as a problem in Nagios.

这篇关于Nagios的插件来检查文件x分钟内创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:06