Ubuntu如何跟踪motd中的“需要系统重启”标志?

我有几个Ubuntu服务器(8.10,9.10),它被设置为自动安装安全更新。 有时这些更新需要重新启动系统,并且这个string显示在motd

 *** System restart required *** 

为了得到关于这些的通知,我打算编写一个Nagiostesting来监视服务器是否需要重启。 所以,我的问题是:

有没有比parsing/etc/motd找出是否需要重启更好的方法?

检查是否存在/var/run/reboot-required

生成motd重启所需部分的脚本是/ usr / lib / update-notifier / update-motd-reboot-required其中包含:

 #!/bin/sh -e # # helper for update-motd if [ -f /var/run/reboot-required ]; then cat /var/run/reboot-required fi 

你的nagios检查可以检查/ var / run / reboot-required的存在。

另外文件'/var/run/reboot-required.pkgs'列出请求重启的软件包。 例如:

 $ cat /var/run/reboot-required.pkgs linux-image-2.6.32-28-generic dbus $ 

在Ubuntu Lucid(10.4)上。

Debian和Ubuntu软件包可以通过执行助手脚本/usr/share/update-notifier/notify-reboot-required来触发在其postinst文件中创build/var/run/reboot-required*

因此,处理重启的“官方”方式由包维护者处理。 我以前在脚本中通过比较/ boot中的mtimes来启动它。

 #!/bin/bash if [ ! -f /var/run/reboot-required ]; then # no reboot required (0=OK) echo "OK: no reboot required" exit 0 else # reboot required (1=WARN) echo "WARNING: `cat /var/run/reboot-required`" exit 1 fi