得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

系统开机时间和重启记录

在 linux 系统上查看系统开机时间和重启记录,在排除 case 中连接 ssh 挂掉的原因中,这也是一个方向,这里记录 7 种方法

  1. who -b
1
2
$ who -b  # time of last system boot,查看最后一次(上次)系统启动的时间
system boot 2020-12-21 17:10
  1. who -r
1
2
$ who -r  # print current runlevel,同时也会输出系统启动时间
run-level 5 2020-08-28 04:57
  1. last reboot
1
2
3
4
5
6
7
$ last reboot -f /var/log/wtmp.1  # 之所以需要 -f 是因为我要查看的是 2020 年的重启记录,而现在正好 2021 年初,新的记录文件中无法查询到
reboot system boot 5.4.0-58-generic Mon Dec 21 17:10 still running
reboot system boot 5.4.0-58-generic Mon Dec 21 15:37 still running
reboot system boot 5.4.0-58-generic Mon Dec 21 15:23 still running
reboot system boot 5.4.0-58-generic Fri Dec 18 13:54 still running

wtmp.1 begins Wed Dec 2 16:07:27 2020
  1. top
1
2
3
4
5
6
7
8
$ top  # up 后表示系统到目前运行了多久时间,所以可以反过来推算系统重启时间
top - 13:35:55 up 13 days, 20:25, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 178 total, 1 running, 138 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.8 us, 0.7 sy, 0.0 ni, 97.4 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1980840 total, 154820 free, 328376 used, 1497644 buff/cache
KiB Swap: 2097148 total, 2025980 free, 71168 used. 1461096 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  1. w
1
2
3
4
$ w  # show who is logged on and what they are doing,up 后表示系统到目前运行了多久时间,所以可以反过来推算系统重启时间
13:36:20 up 13 days, 20:26, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
test pts/0 10.140.14.68 13:14 4.00s 0.06s 0.00s w
  1. uptime
1
2
$ uptime  # tell how long the system has been running,up 后表示系统到目前运行了多久时间
13:36:54 up 13 days, 20:26, 1 user, load average: 0.00, 0.00, 0.00
  1. 借助 /proc/uptime
1
2
3
4
5
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago"
2020年 12月 21日 星期一 17:10:11 CST

$ date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
2020-12-21 17:10:11

be yourself, everyone else is already taken.