开发者

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

I am writing a bash script (for 开发者_如何学编程apt-get based OS's) that automates the installations process of various programs. In this process I run "apt-get -fy update" and "apt-get -fy upgrade" sometimes. In the process of upgrading, occasionally, a restart is required.

My question: is there a way of testing if the system is asking for a restart after running "apt-get -fy upgrade"? I am trying to write the script for it to run from beginning to end without human any intervention.

Thank you.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜