2

I have a NVR system that recording video surveilance into a linux server. This NVR system sometimes stops recordings (Bug) and I wanna know when that happens.

I'm looking into using the find command with a into a script and a cronjob to send me an email if no files is created within the passed 60 minutes.

The command I came up with is:

find /path/to/folder/* -name "*.ts" -mmin +0 -mmin -60 -exec echo "No New Recording Available" \; | mail -s "PP-NVR" me@server.com

But this command only sends me a list of "No New Recording Available" for the files older than 60 minutes

No New Recordinf Available
No New Recordinf Available
No New Recordinf Available
No New Recordinf Available
No New Recordinf Available
...

Can anyone please help!

EDIT: This is the script I came up with but it doesn't seem like it's working correctly:

#!/bin/sh

if test 'find /path_to_folder/* -name "*.ts" -mmin +1 -mmin -10'
then
echo "No New Recording Available" | mail -s "PP-NVR" me@server.com
fi
Youssef Karami
  • 75
  • 1
  • 13

2 Answers2

0

You could try combining this run a unix shell command if the output doesn't have a specific number of lines

With

vagrant@puppet ~]$ find . -name '*.ts' -mmin -1 | wc -l
0
[vagrant@puppet ~]$ touch blah.ts
[vagrant@puppet ~]$ find . -name '*.ts' -mmin -1 | wc -l
1

So:

[vagrant@puppet ~]$ ./alert.sh
No new files
[vagrant@puppet ~]$ echo >> blah.ts
[vagrant@puppet ~]$ ./alert.sh
[vagrant@puppet ~]$ cat alert.sh
#!/bin/sh

newfiles=$(find . -name '*.ts' -mmin -1 | wc -l)

if [[ $newfiles -eq 0 ]] ; then
    echo "No new files"
fi
[vagrant@puppet ~]$
Community
  • 1
  • 1
Donald_W
  • 1,773
  • 21
  • 35
0

I don't have a solution using find, but you can use inotifywait (in inotify-tools) to set up a watcher, like this:

inotifywait -r -e modify -t 60 /path/to/folder

and check $? for the value 2 which means that it has timed out after 60 seconds (-t 60) without files being modified (-e modify) inside the /path/to/folder and it's sub-folders (-r).

FrodeTennebo
  • 531
  • 3
  • 13
  • Inotify is a Linux kernel feature. inotifyway is a utility which uses that feature. You can install it using your distribution's package management system, e.g. **apt-get install inotify.tools**. – FrodeTennebo Sep 18 '15 at 06:37