在Linux系统中,如何查看系统什么时候执行了shutdown命令关闭服务器了呢?
方法1:使用 last -x|grep shutdown 查看shutdown的历史记录
[root@mylnx20 log]# last -x|grep shutdown
shutdown system down 2.6.32-504.el6.x Thu Jun 23 17:30 - 09:03 (15:33)
shutdown system down 2.6.32-504.el6.x Sun Apr 10 23:29 - 23:29 (00:00)
shutdown system down 2.6.32-504.el6.x Sun Apr 10 23:25 - 23:27 (00:02)
shutdown system down 2.6.32-504.el6.x Sun Apr 10 23:24 - 23:24 (00:00)
shutdown system down 2.6.32-504.el6.x Thu Mar 3 00:11 - 00:12 (00:00)
shutdown system down 2.6.32-504.el6.x Fri Jun 26 10:50 - 10:50 (00:00)
shutdown system down 2.6.32-504.el6.x Fri Jun 26 10:35 - 10:35 (00:00)
shutdown system down 2.6.32-504.el6.x Thu Jun 25 10:37 - 10:37 (00:00)
shutdown system down 2.6.32-504.el6.x Sat Jun 13 23:10 - 23:10 (00:00)
shutdown system down 2.6.32-504.el6.x Sat Jun 13 22:54 - 22:54 (00:00)
如下所示,可以使用下面命令查看最后一次shutdown的时间。
[root@mylnx20 log]# last -x|grep shutdown | head -1
shutdown system down 2.6.32-504.el6.x Thu Jun 23 17:30 - 09:03 (15:33)
方法2:通过/var/log/messages日志查看shutdown的记录
[root@localhost log]# more /var/log/messages | grep "shutdown"
[root@localhost log]# more /var/log/messages.1 | grep "shutdown"
Jun 13 11:55:37 localhost shutdown[23387]: shutting down for system halt
[root@localhost log]#
这种方法也有个弊端,如果messages日志被循环覆盖了,那么这种方法也检查不出什么时候重启过,另外这种方法在有些版本的Linux是无效的,例如在Red Hat Enterprise Linux Server release 6.6 下,你执行了shutdown -h now后,message如下所示,根本没有shutdown相关字眼
[root@cluster-00 log]# more /var/log/messages | grep "acpid: exiting"
Jun 24 11:43:49 cluster-00 acpid: exiting
遗憾的是这两种方法都无法定位是那个客户端发出的shutdown命令。只能看到shutdown命令执行的时间。