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?

1 Answer 1

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:

[email protected]

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

3
  • thanks heaps for both the encouragement and the links. I have scripted gmail emails before but I am surprised how simple it seems to extend that to SMS. I am, however having some difficulty determining the mailto address of my service, which is Amaysim here in Australia. I did find a Gmail addon which works to send email to text and the mailto address in the sent archive appears too be: [email protected]
    – Hazy
    Commented Mar 21, 2018 at 1:37
  • ..however that address fails when I try to use it in either ssmtp or mailx with this error: Action: failed Final-Recipient: rfc822;[email protected] Status: 5.0.0
    – Hazy
    Commented Mar 21, 2018 at 1:48
  • It is sometimes difficult finding the SMS address. For me, it is pretty simple since I set up Google Voice. All I have to do is send a text to my Google Voice number, and I have it set up to also forward to email. That way, in both places you can see the originating mailto: address for the text messages.
    – SDsolar
    Commented Mar 21, 2018 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.