How to detect whether apt-get requires a reboot using Bash? How to detect whether apt-get requires a reboot using Bash? bash bash

How to detect whether apt-get requires a reboot using Bash?


Use the file /var/run/reboot-required which does exactly what you want. So we will have this:

apt-get update && apt-get -fy upgrade && [ -f /var/run/reboot-required ] && shutdown -r now 


I don't recall whether apt-get actually gives you a predictably formatted message informing you whether a restart is necessary, but if it does you could just check the output, e.g. something like apt-get -fy update | grep -q 'fill in restart message pattern' && reboot.

Another probably less reliable alternative is to use checkrestart from the debian-goodies package.


If you do a

apt-get -fy update && shutdown -r now

it will respect the order and will update until finish and finally restart your server.