Skip to content
Advertisement

remotely determine using ssh IF a machine needs to be rebooted [closed]

There are plenty of examples of HOW to reboot a linux machine via SSH. However, in my case I want to check IF a linux machine needs to be rebooted via SSH. I have an agent that checks a machine for various metrics and reports that back to a central alarm console. I want to add the ability to check if a machine requires a reboot since some of them have security updates automatically installing.

I don’t want to have to enable something on each machine as I prefer to run one script from one location preferably with a single command to check remotely.

EDIT: To clarify, I was looking for a file on a machine that would indicate whether a machine requires a reboot. I then wanted to check for the existence of that file (or something else) remotely using SSH where I am already doing other checks on a group of machines on a nightly basis. I didn’t necessarily want to trigger a reboot if it was determined a reboot is required.

The answer I was looking for is below that’s referencing /var/run/reboot-required which lead me to to this link.

Advertisement

Answer

You can check if the file /var/run/reboot-required exists.
In a bash script, you can use:

#!/bin/bash
if [ -f /var/run/reboot-required ]; then
  echo 'A reboot is required'
  restart -r now
fi

That way, the script will reboot your machine if a required reboot is pending.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement