How can I tell, from the command line, whether the machine requires a reboot?
You can simply check if the file /var/run/reboot-required
exists or not.
For example, any of these would tell you "no such file" or "file not found" if you do not need to reboot, otherwise (if you need to reboot) the file would exist and these commands would show information about the file:
file /var/run/reboot-required
stat /var/run/reboot-required
ls /var/run/reboot-required
In a bash script, you can use:
#!/bin/bash
if [ -f /var/run/reboot-required ]; then
echo 'reboot required'
fi
In the package debian-goodies is a command named checkrestart
which is quite useful. Its output can help you avoid a full reboot.
It tells you which running applications have loaded shared libraries that were upgraded while the application was running. You then restart the applications and services manually and avoid a full reboot. Does not help with kernel upgrades, though.
Normally if the file
/var/run/reboot-required
exists you should reboot. You can see if this file is there by using this simple command in gnome-terminal.
ls /var/run/reboot-required