You can use the following tools to see how long a Linux or Unix-like system has been running:
◆uptime: Tell you how long the server has been running.
◆lastt: Display restart and shutdown time.
◆tuptime: report the running time history and running time statistics of the system, which refers to the running time between restarts. Similar to the uptime command, but the output is more interesting.
Find out the time and date the system was last restarted
You can use the following commands to get the last restart and shutdown time and date of the Linux operating system (also available on OSX/Unix-like systems):
### 显示系统重启和关机时间who -blast rebootlast shutdown### 开机信息uptimecat /proc/uptimeawk '{ print "up " $1 /60 " minutes"}' /proc/uptimew
Sample output:
Figure 1: Multiple Linux commands for finding the server boot time
Say hello to tuptime
The tuptime command line tool can report the following information on Linux-based systems:
◆Statistics of system startup times
◆Registration*** start time (that is, installation time)
◆Statistics of normal shutdown and unexpected shutdown
◆Average startup time and downtime
◆Current boot time
◆***Startup and failure shutdown rate since startup
◆Cumulative system startup time, downtime and total
◆Report each startup, startup time, shutdown and downtime
installation
Enter the following command to clone the git repository to the Linux system :
$ cd /tmp$ git clone https://github.com/rfrail3/tuptime.git$ ls$ cd tuptime$ ls
Sample output:
Figure 2: Clone the git repository
Make sure you install Python v2.7 with sys, optparse, os, re, string, sqlite3, datetime, disutils and locale modules.
You can install it like this:
$ sudo tuptime-install.sh
Or, you can install it manually (based on systemd or non-systemd):
$ sudo cp /tmp/tuptime/latest/cron.d/tuptime /etc/cron.d/tuptime
If the system is systemd, copy the service file and enable:
$ sudo cp /tmp/tuptime/latest/systemd/tuptime.service /lib/systemd/system/$ sudo systemctl enable tuptime.service
If the system is not systemd, copy the initialization file:
$ sudo cp /tmp/tuptime/latest/init.d/tuptime.init.d-debian7 /etc/init.d/tuptime$ sudo update-rc.d tuptime defaults
run
Just enter the following command:
$ sudo tuptime
Sample output:
Figure 3: tuptime is working
After updating the kernel once, I restarted the system, and then entered the same command again:
$ sudo tuptimeSystem startups: 2 since 03:52:16 PM 08/21/2015System shutdowns: 1 ok - 0 badAverage uptime: 7 days, 16 hours, 48 minutes and 3 secondsAverage downtime: 2 hours, 30 minutes and 5 secondsCurrent uptime: 5 minutes and 28 seconds since 06:23:06 AM 09/06/2015Uptime rate: 98.66 %Downtime rate: 1.34 %System uptime: 15 days, 9 hours, 36 minutes and 7 secondsSystem downtime: 5 hours, 0 minutes and 11 secondsSystem life: 15 days, 14 hours, 36 minutes and 18 seconds
You can modify the date and time format as follows:
$ sudo tuptime -d '%H:%M:%S %m-%d-%Y'
Sample output:
System startups: 1 since 15:52:16 08-21-2015System shutdowns: 0 ok - 0 badAverage uptime: 15 days, 9 hours, 21 minutes and 19 secondsAverage downtime: 0 secondsCurrent uptime: 15 days, 9 hours, 21 minutes and 19 seconds since 15:52:16 08-21-2015Uptime rate: 100.0 %Downtime rate: 0.0 %System uptime: 15 days, 9 hours, 21 minutes and 19 secondsSystem downtime: 0 secondsSystem life: 15 days, 9 hours, 21 minutes and 19 seconds
Calculate the time of each startup, startup time, shutdown and downtime:
$ sudo tuptime -e
Sample output:
Startup: 1 at 03:52:16 PM 08/21/2015Uptime: 15 days, 9 hours, 22 minutes and 33 seconds System startups: 1 since 03:52:16 PM 08/21/2015System shutdowns: 0 ok - 0 badAverage uptime: 15 days, 9 hours, 22 minutes and 33 secondsAverage downtime: 0 secondsCurrent uptime: 15 days, 9 hours, 22 minutes and 33 seconds since 03:52:16 PM 08/21/2015Uptime rate: 100.0 %Downtime rate: 0.0 %System uptime: 15 days, 9 hours, 22 minutes and 33 secondsSystem downtime: 0 secondsSystem life: 15 days, 9 hours, 22 minutes and 33 seconds
via: http://www.cyberciti.biz/hardware/howto-see-historical-statistical-uptime-on-linux-server/
Author: Vivek Gite Translator: GOLinux proofread: wxy
The above is the Linux-related knowledge shared by Liangxu Tutorial Network for all friends.