我使用过的Linux命令之ac - 在线时间统计

我使用过的Linux命令之ac - 在线时间统计

本文链接:http://codingstandards.iteye.com/blog/774457   (转载请注明出处)

用途说明

打印用户连接的时间 Prints statistics about users' connect time.

ac命令根据当前的/var/log/wtmp文件中的登录进入和退出来报告用户连接的时间(小时),如果不使用标志,则报告总的时间【2】。也就是统计用户的在线时间。

常用参数

-d 按每天的统计数据打印。 Print totals for each day rather than just one big total at the end.

-y 在显示日期的时候输出年份。 Print year when displaying dates.

-p 打印每个账号的总的连接时间。 Print time totals for each user in addition to the usual everything-lumped-into-one value.

使用示例

示例一

[root@web ~]# ac
        total     1366.71

[root@web ~]# ac -d -y
Jun 28 2010     total        5.48
Jun 29 2010     total       15.97
Jun 30 2010     total       25.38
Jul  1 2010     total       33.62
Jul  3 2010     total       14.17
Jul  4 2010     total       24.94
Jul  5 2010     total        4.35
Jul  6 2010     total       46.59
Jul  7 2010     total       67.27
Jul  8 2010     total       41.07
Jul  9 2010     total       81.77
Jul 10 2010     total       45.72
Jul 12 2010     total       35.99
Jul 13 2010     total       52.14
Jul 14 2010     total       50.01
Jul 15 2010     total       37.90
Jul 16 2010     total       39.18
Jul 17 2010     total        6.59
Jul 18 2010     total        8.08
Jul 19 2010     total       10.93
Jul 20 2010     total        5.56
Jul 21 2010     total       11.23
Jul 23 2010     total        1.49
Aug  1 2010     total        6.91
Aug  9 2010     total        9.36
Aug 10 2010     total       34.48
Aug 11 2010     total       24.88
Aug 12 2010     total       24.21
Aug 13 2010     total       38.00
Aug 14 2010     total        9.05
Aug 19 2010     total       26.42
Aug 20 2010     total       62.44
Aug 21 2010     total        9.58
Aug 23 2010     total       22.59
Aug 25 2010     total        0.17
Aug 27 2010     total        4.56
Aug 30 2010     total        1.03
Aug 31 2010     total        9.67
Sep  1 2010     total        1.51
Sep  2 2010     total        4.82
Sep  5 2010     total        3.71
Sep  6 2010     total        0.38
Sep  7 2010     total       44.68
Sep  8 2010     total        0.65
Sep  9 2010     total       31.65
Sep 10 2010     total       31.27
Sep 11 2010     total        0.41
Sep 12 2010     total        9.70
Sep 13 2010     total       14.57
Sep 14 2010     total       27.97
Sep 15 2010     total       13.19
Sep 16 2010     total       14.82
Sep 17 2010     total       14.37
Sep 18 2010     total       16.20
Sep 19 2010     total       30.74
Sep 20 2010     total       27.55
Sep 21 2010     total       27.44
Sep 24 2010     total        3.46
Sep 25 2010     total       21.43
Sep 26 2010     total       19.55
Sep 27 2010     total       14.24
Today           total       44.09

示例二

[root@web186 hycu2]# ac
        total       37.42

[root@web186 hycu2]# ac -d -y
Sep  1 2010     total        3.77
Sep  9 2010     total        6.70
Sep 13 2010     total        8.56
Sep 14 2010     total        4.75
Sep 15 2010     total       11.15
Sep 20 2010     total        2.19
Today           total        0.35

示例三

[web@hnweb1 ~]$ ac
        total      307.32

[web@hnweb1 ~]$ ac -d -y
Sep  2 2010     total        3.18
Sep  7 2010     total        3.19
Sep  8 2010     total        8.00
Sep  9 2010     total        3.03
Sep 13 2010     total        3.68
Sep 15 2010     total        4.16
Sep 17 2010     total        0.09
Sep 19 2010     total        0.07
Sep 20 2010     total        8.86
Sep 21 2010     total       25.89
Sep 25 2010     total      108.75
Sep 26 2010     total       50.91
Today           total       87.56

[web@hnweb1 ~]$ ac -d
Sep  2  total        3.18
Sep  7  total        3.19
Sep  8  total        8.00
Sep  9  total        3.03
Sep 13  total        3.68
Sep 15  total        4.16
Sep 17  total        0.09
Sep 19  total        0.07
Sep 20  total        8.86
Sep 21  total       25.89
Sep 25  total      108.75
Sep 26  total       50.91
Today   total       87.99

[web@hnweb1 ~]$ ac -p
        web                                211.76
        smp                                  0.09
        vas                                  1.98
        webipc                              93.99
        total      307.83

2010年10月8日晚上重新在这台上执行了上面的命令,结果如下:

[web@hnweb1 ~]$ ac -d -y
Today           total        3.14
[web@hnweb1 ~]$ ac -d
Today   total        3.15
[web@hnweb1 ~]$ ac -p
        web                                  0.01
        webipc                               3.14
        total        3.16
[web@hnweb1 ~]$

问题来了,只显示了本月(当天)的数据,上月的数据不见了!!!

问题思考

1. ac统计的时间是如何计算的?

2. ac -d显示的数据为什么不包括当天的数据?如上所示,今天是2010年9月28日,但打印出来的都没有包括今天的。

3. 怎么显示上月的数据?

相关资料

【1】Computer Hope Linux / Unix ac command

【2】Linux521.com linux ac 命令

【3】Linux人 Ac

返回 我使用过的Linux命令系列总目录

猜你喜欢

转载自codingstandards.iteye.com/blog/774457