我正在尝试将 bash 脚本转换为 nagios 插件
该脚本将运行 find 命令来查看文件是否在 x 分钟内创建:
#!/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 插件:
#!/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
但是每次运行时我都会收到错误消息:
./check_nvr.sh: line 9: syntax error near unexpected token `[[$newfiles'
./check_nvr.sh: line 9: `if [[$newfiles -ne 0]]'
我不知道如何解决这个问题。我将不胜感激任何指导!
编辑:
我将脚本更改为:
#!/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
但是现在我运行脚本后没有得到输出
最佳答案
@Donald_W
我通过将脚本更改为:
#!/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 Dashboard 中并没有显示主机没有录制。我停止录制只是为了测试,当我运行脚本时收到警告消息,但它在 Nagios 中没有显示为问题。
关于linux - 用于检查文件在 x 分钟内创建的 Nagios 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32657539/