Bash - 如何检测apt-get是否需要重启

Rog*_*ger 18 bash restart command-line-interface

我正在编写一个bash脚本(用于基于apt-get的OS),它可以自动执行各种程序的安装过程.在这个过程中,我有时会运行"apt-get -fy update"和"apt-get -fy upgrade".在升级过程中,偶尔需要重启.

我的问题:有没有办法测试系统是否在运行"apt-get -fy upgrade"后要求重启?我正在尝试编写脚本,使其从头到尾运行,无需任何干预.

谢谢.

Gcm*_*loc 35

使用文件/ var/run/reboot-required,它完全符合您的要求.所以我们会这样:

apt-get update && apt-get -fy upgrade && [ -f /var/run/reboot-required ] && shutdown -r now 
Run Code Online (Sandbox Code Playgroud)