Re: EMail on unexpected reboot

From: Justin Teague <arcadellama_at_posteo.net>
Date: Wed, 15 May 2024 20:04:04 UTC
> On 15 May 2024, at 14:25, Dan Mahoney (Ports) wrote:
> Yes, that happens *every* reboot, and I was asking if the system had a way of detecting only “unclean” reboots.  Some checkfile that’s set on clean shutdown, for example.

I know that `last reboot` will show ‘boot’ and ‘shutdown’ entries the accounting database. I haven’t tested this myself, but I suppose an ‘unclean’ reboot would mean you would have two consecutive ‘boot’ entries? (I’m not in a place to test it at the moment.)

If so, then something like the following should work:

@reboot if [ “$(last reboot | sed -n '2p' | cut -d ' ' -f1)” = “boot” ]; then <foo>; fi

- Justin