这是我使用的测试脚本:
last_reboot=$(last reboot | grep 'still running' | awk '{for (i=5; i<=NF; i++) printf $i FS}' | awk '{for (i=1; i<=NF - 2; i++) printf $i FS}')
if [ "$last_reboot" ]; then
date -d "$last_reboot" '+last reboot: %Y-%m-%d'
fi
days=$(uptime | awk '{print $3}')
hours=$(uptime | awk '{print $5}' | sed -E 's/,$//')
h=$(echo "$hours" | cut -d: -f 1)
m=$(echo "$hours" | cut -d: -f 2)
date -d "- $days days - $h hours - $m minutes" '+uptime: %Y-%m-%d' …
Run Code Online (Sandbox Code Playgroud) 我last
在 RHEL的命令输出中看到一个可疑的模式:
$ last reboot
reboot system boot 3.10.0-514.21.1. Wed Dec 13 10:25 - 11:53 (01:28)
reboot system boot 3.10.0-514.21.1. Mon Oct 30 16:23 - 11:53 (43+20:30)
reboot system boot 3.10.0-514.21.1. Fri Oct 20 16:53 - 11:53 (53+20:00)
reboot system boot 3.10.0-514.21.1. Mon Oct 16 09:21 - 11:53 (58+03:32)
reboot system boot 3.10.0-514.21.1. Fri Aug 25 15:53 - 11:53 (109+21:00)
reboot system boot 3.10.0-514.21.1. Tue Aug 22 15:36 - 11:53 (112+21:16)
reboot system boot 3.10.0-514.21.1. Fri Jul 21 …
Run Code Online (Sandbox Code Playgroud)