Occasionally, you’ll make a change in Linux that might be a bit precarious – you commit the change with a hesitation anticipation of a problem or uncertainty on the next reboot. In these cases, it may be desirable to schedule a shutdown if nothing is done within a certain time period.
I do this frequently when I’m testing changes to a Raspberry Pi that doesn’t have an off button. This reduces the likelihood that I need to turn off the device by removing power (a problematic shut-off method that can cause problems with the SD card).
If systemd is available, you can create a new timer that executes after a set amount of time.
We’ll create a systemd unit that executes after the multi-user target has completed.
Create a small script to trigger the auto-reboot.
Description="Automatically power off after a period of time."
Finally create the symlink into the multi-user.target directory.
ln -s ../auto-poweroff.sh