I'm trying to convert a bash script to nagios plugin
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
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]]'
I'm not sure how I can resolve this. I'd appreciate any guidance!
EDIT:
I changed the script to:
#!/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