我有以下“自定义”顶部命令,用于从“顶部”命令日志中提取时间戳信息:
top -b -d 1 -n 60 | awk '{now=strftime("%Y-%m-%d %T ");print now $0}' > $(date +"%Y%m%d%H%M")_top.log
我以批处理模式运行60秒钟。但是,正如您在我的日志中看到的那样,由于某些“未知”原因,快照的最后一个过程显示了下一个时间戳。是什么原因,我该如何纠正?
2019-05-19 03:56:21 top - 03:56:21 up 1 day, 13:24, 1 user, load average: 1.63, 1.52, 1.56
2019-05-19 03:56:21 Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie
2019-05-19 03:56:21 %Cpu(s): 53.6 us, 40.0 sy, 0.0 ni, 5.0 id, 0.0 wa, 0.0 hi, 1.4 si, 0.0 st
2019-05-19 03:56:21 KiB Mem : 491172 total, 419048 free, 15592 used, 56532 buff/cache
2019-05-19 03:56:21 KiB Swap: 524284 total, 519188 free, 5096 used. 464680 avail Mem
2019-05-19 03:56:21
2019-05-19 03:56:21 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2019-05-19 03:56:21 21404 root 20 0 3192 2040 1720 R 13.5 0.4 0:10.50 top
2019-05-19 03:56:21 22400 root 20 0 3192 2024 1708 S 12.8 0.4 0:02.76 top
2019-05-19 03:56:21 467 root 20 0 3148 992 852 S 4.3 0.2 82:08.48 bash
2019-05-19 03:56:21 22401 root 20 0 3380 1916 1736 S 2.1 0.4 0:00.41 awk
2019-05-19 03:56:21 7 root 20 0 0 0 0 S 0.7 0.0 16:19.62 rcu_preempt
2019-05-19 03:56:21 22403 root 20 0 3380 1912 1736 S 0.7 0.4 0:00.03 awk
2019-05-19 03:56:21 1 root 20 0 2480 180 160 S 0.0 0.0 0:13.28 init
2019-05-19 03:56:21 22619 root 20 0 1988 892 836 S 0.0 0.2 0:00.00 sleep
2019-05-19 03:56:23 28316 root 20 0 0 0 0 S 0.0 0.0 0:00.17 kworker/u2:1
2019-05-19 03:56:23
2019-05-19 03:56:23 top - 03:56:23 up 1 day, 13:24, 1 user, load average: 1.63, 1.52, 1.56
2019-05-19 03:56:23 Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie
2019-05-19 03:56:23 %Cpu(s): 53.6 us, 39.9 sy, 0.0 ni, 5.1 id, 0.0 wa, 0.0 hi, 1.4 si, 0.0 st
2019-05-19 03:56:23 KiB Mem : 491172 total, 419048 free, 15592 used, 56532 buff/cache
2019-05-19 03:56:23 KiB Swap: 524284 total, 519188 free, 5096 used. 464680 avail Mem
2019-05-19 03:56:23
2019-05-19 03:56:23 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2019-05-19 03:56:23 22400 root 20 0 3192 2024 1708 S 13.9 0.4 0:02.95 top
2019-05-19 03:56:23 21404 root 20 0 3192 2040 1720 R 13.1 0.4 0:10.68 top
2019-05-19 03:56:23 467 root 20 0 3148 992 852 S 4.4 0.2 82:08.54 bash
2019-05-19 03:56:23 21405 root 20 0 3380 1916 1736 S 2.2 0.4 0:01.59 awk
2019-05-19 03:56:23 7 root 20 0 0 0 0 S 0.7 0.0 16:19.63 rcu_preempt
2019-05-19 03:56:23 1 root 20 0 2480 180 160 S 0.0 0.0 0:13.28 init
2019-05-19 03:56:23 22619 root 20 0 1988 892 836 S 0.0 0.2 0:00.00 sleep
2019-05-19 03:56:24 28316 root 20 0 0 0 0 S 0.0 0.0 0:00.17 kworker/u2:1
2019-05-19 03:56:24
2019-05-19 03:56:24 top - 03:56:24 up 1 day, 13:24, 1 user, load average: 1.58, 1.52, 1.56
2019-05-19 03:56:24 Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie
2019-05-19 03:56:24 %Cpu(s): 52.6 us, 41.6 sy, 0.0 ni, 4.4 id, 0.0 wa, 0.0 hi, 1.5 si, 0.0 st
2019-05-19 03:56:24 KiB Mem : 491172 total, 418896 free, 15660 used, 56616 buff/cache
2019-05-19 03:56:24 KiB Swap: 524284 total, 519188 free, 5096 used. 464612 avail Mem
2019-05-19 03:56:24
2019-05-19 03:56:24 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2019-05-19 03:56:24 21404 root 20 0 3192 2040 1720 R 13.7 0.4 0:10.87 top
2019-05-19 03:56:24 22400 root 20 0 3192 2024 1708 S 12.9 0.4 0:03.13 top
2019-05-19 03:56:24 467 root 20 0 3148 992 852 S 3.6 0.2 82:08.59 bash
2019-05-19 03:56:24 21405 root 20 0 3380 1916 1736 S 2.2 0.4 0:01.62 awk
2019-05-19 03:56:24 22401 root 20 0 3380 1916 1736 S 2.2 0.4 0:00.47 awk
2019-05-19 03:56:24 3 root 20 0 0 0 0 S 0.7 0.0 3:54.70 ksoftirqd/0
2019-05-19 03:56:24 1 root 20 0 2480 180 160 S 0.0 0.0 0:13.28 init
2019-05-19 03:56:24 2 root 20 0 0 0 0 S 0.0 0.0 0:00.51 kthreadd
2019-05-19 03:56:24 4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
2019-05-19 03:56:24 22619 root 20 0 1988 892 836 S 0.0 0.2 0:00.00 sleep
2019-05-19 03:56:25 28316 root 20 0 0 0 0 S 0.0 0.0 0:00.17 kworker/u2:1
2019-05-19 03:56:25
2019-05-19 03:56:25 top - 03:56:25 up 1 day, 13:24, 1 user, load average: 1.58, 1.52, 1.56
2019-05-19 03:56:25 Tasks: 113 total, 1 running, 112 sleeping, 0 stopped, 0 zombie
2019-05-19 03:56:25 %Cpu(s): 59.6 us, 34.6 sy, 0.0 ni, 5.1 id, 0.0 wa, 0.0 hi, 0.7 si, 0.0 st
2019-05-19 03:56:25 KiB Mem : 491172 total, 418896 free, 15660 used, 56616 buff/cache
2019-05-19 03:56:25 KiB Swap: 524284 total, 519188 free, 5096 used. 464612 avail Mem
2019-05-19 03:56:25
2019-05-19 03:56:25 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2019-05-19 03:56:25 21404 root 20 0 3192 2040 1720 R 13.7 0.4 0:11.06 top
2019-05-19 03:56:25 22400 root 20 0 3192 2024 1708 S 13.7 0.4 0:03.32 top
2019-05-19 03:56:25 467 root 20 0 3148 992 852 S 4.3 0.2 82:08.65 bash
2019-05-19 03:56:25 22401 root 20 0 3380 1916 1736 S 2.2 0.4 0:00.50 awk
2019-05-19 03:56:25 1 root 20 0 2480 180 160 S 0.7 0.0 0:13.29 init
2019-05-19 03:56:26 313 message+ 20 0 11780 4 4 S 0.0 0.0 0:00.00 dbus-daemon
2019-05-19 03:56:26 325 root 20 0 6216 4 4 S 0.0 0.0 0:00.01 sshd
2019-05-19 03:56:26 402 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kauditd
2019-05-19 03:56:26 452 root 20 0 3148 1452 1304 S 0.0 0.3 1:07.39 bash
2019-05-19 03:56:26 6488 root 20 0 3148 2004 1892 S 0.0 0.4 0:00.01 sh
2019-05-19 03:56:26 22393 root 20 0 3916 1744 1604 S 0.0 0.4 0:00.00 crond
2019-05-19 03:56:26 22397 root 20 0 3148 1996 1880 S 0.0 0.4 0:00.01 sh
2019-05-19 03:56:26 22619 root 20 0 1988 892 836 S 0.0 0.2 0:00.00 sleep
2019-05-19 03:56:27 28316 root 20 0 0 0 0 S 0.0 0.0 0:00.17 kworker/u2:1