2

I have had a Raspberry Pi Zero W controlled, time-lapse camera taking pictures, of a construction project, every 60 seconds for nearly three months and recently it's started failing. I suspect the issue lies in the camera hard or software (CHDKPTP), not the Pi. So I need the Pi to tell me when it happens.

The system is running Rasbian Stretch.

Image are uploaded immediately to my web hosting and added to a web gallery, so to check that the system it's working I have to either use an FTP program, or look at the gallery page. This is inconvenient and I sometimes find I've missed several hours of images when the camera has crashed.

So I am looking for unix tool to keep an eye on the uploads and alert me by email, or even better, SMS, a few minutes after the files stop arriving - during the daily capture period, of 7:30am - 4:30pm.

inotify looks promising but I can't find reference to alert on 'failed but expected' file creation events, only alerting on 'new' file creation events.

Any suggestions?

SDsolar
  • 2,378
  • 8
  • 26
  • 43
Hazy
  • 21
  • 2

1 Answers1

2

You are correct about ifnotify - and kudos to you for discovering it. It cannot react to the absence of an event.

What you are going to want is a script or a python program to do as you described.

Either can monitor a directory to see if it has had a file added.

It is not clear to me whether your stream of files means that every XX seconds a NEW file is added.

If so, it is trivial to do a script that is regularly run as a cron script that does a ls -al | wc >./tmp.tmp then some logic to determine whether the length of ./tmp.tmp is getting longer.

Python works much the same. You would import os then use os.listdir('.') to get the list of the current directory. I would save the directory as a file, then each time use this to both compare with the file and to then save it for next time.

Note that the most frequently that cron can launch a job is down to the minute.

Using cron is much more efficient than leaving a program running all the time comparing the clock, unless (for example) you use a sleep 1 command in a script to release the processor for a second each loop.


As for getting the alerts, see this Q&A:

Simplest way to send one-line mail out via command line using gmail?

It can send SMS if you know the mailto: link to your phone.

Each carrier has a different method, similar to this:

19074561234@.txt.att.com

You will need to look that part up and just use it as your target email address as described in the link above.

SDsolar
  • 2,378
  • 8
  • 26
  • 43