1

Is there a quick and easy method to send an email (I already have automatic emails coming from the server for other events - I just need to be able to send one for this specific event) if a USB port restarts and, by extension, an external drive goes offline?

I installed a new CCTV system in my father in law's house last year, and as an added bonus, I bought him a Raspberry PI, set it up as a VPN and file server, and set the cameras to directly record on motion to some NFS shares I've set up on an external drive on the PI so that there were two copies of anything important if someone had the brains to steal the NVR.

But the cameras kept losing the storage and required a reboot to bring the storage back online.

I assumed this was a POE issue, as the cameras themselves were also sometimes rebooting when powered directly from the NVR, but after installing a POE switch and changing the network config a bit, that has ceased.

I checked today though and found the cameras had again lost their secondary storage. Investigating further, I narrowed down the time, and checked the syslog on the PI. I found that it had suffered a USB issue.

usb 1-1.1-port2: disabled by hub (EMI?), re-enabling...

This was followed by thousands of messages regarding the drives going offline, coming online, and the cameras attempting to access the NFS shares.

What I want is for the system to ping me an email if this event is logged to the syslog file, or simply when one of the filesystems goes offline, so I can ring him to see if he's doing anything specific.

It may be something as simply as a dodgy USB lead or drive enclosure (we got a self powered enclosure to save the PI from having to spin a 3.5" HDD) so it may even be the PSU, but I'd like to try to identify anything happening while the failures are occurring before getting a new HDD enclosure that may not solve the issue.

The PI itself is powered by the official Pi 3 psu. The casing of the PI is aluminium (I can't remember the specific one I bought but it's all metal to act as a heat sink) but it's fairly hidden away in behind the monitor in his study so it's unlikely to be getting shifted about much and shorting against anything.

Edit at request of K7AAY

The Pi is running Raspbian 9

I will be modifying the following script if the solution involves a method that can run a script.

#bin/sh
IPADDRESS=$(curl https://wtfismyip.com/text)
if [ "$IPADDRESS" != "$(cat /home/will/scripts/.current_ip)" ]
then
dt=$(date)
echo "Your new IP address as of ${dt} is ${IPADDRESS} \r \r FTB" | mail -s "IvanPI IP address change" **********@gmail.com
echo "$IPADDRESS" >| /home/will/scripts/.current_ip
echo "$dt $IPADDRESS" >> /home/will/scripts/.iphistory
fi

the only command I need to issue if the above event occurs will be

echo "External HDD offline/USB restarted at ${dt} \r \r FTB" | mail -s "IvanPI HDD Offline" *************@gmail.com

I just need to know how to trigger that command to occur if the HDD goes offline/Filesystem goes offline/USB port restarts.

Any of these events would be suitable to generate the trigger for the email, since they're all essentially the same thing.

1

Trafikito and monit are reasonably lightweight services which can monitor your drive, and if it fails, go check the USB port status. Then, either can mail out a message. Suggest you review their feature sets and see which you prefer.

  • Monit looks as if it will do exactly what I need if the filesystem has an error. Thank you. – Will Feb 9 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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