Home:ALL Converter>Create shell script to reboot linux in case of incorrect shutdown

Create shell script to reboot linux in case of incorrect shutdown

Ask Time:2017-07-11T01:10:03         Author:Ernani

Json Formatter

I have Raspbian Jessie 8 running in a Raspberry Pi 3. There are 3 JavaScript services that are automatically started by PM2.

However, if the Raspberry is shutdown incorrectly, e.g., if the energy cable is removed, the services don't start.

They only start automatically if the Raspberry is shutdown properly, e.g., using sudo reboot.

I need a shell script that checks if the Raspberry was incorrectly shutdown and, if it was, to be rebooted using sudo reboot.

I saw here and here how to create a simple reboot script and here how to check if a service is running, but found nothing on how to check for an improper shutdown. Can anyone tell me how?

Author:Ernani,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45017960/create-shell-script-to-reboot-linux-in-case-of-incorrect-shutdown
yy