【发布时间】:2015-12-15 22:17:37
【问题描述】:
我正在尝试将 bash 脚本转换为 nagios 插件
该脚本将运行一个查找命令来查看是否在 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
但是现在我运行脚本后没有得到输出
【问题讨论】:
-
我不是专家,但您不需要在
[[之后和]]之前有空格吗? -
无论有没有空格,我都会收到相同的错误消息
-
对不起,我的 if 语句总是写成
if [ $test == 0 ] then...else..fi。 -
@NoseKnowsAll 它没有改变任何东西......