Linux 登录统计小工具——ac
安装
redhat/centos/rocky
# yum provides ac
psacct-6.6.1-13.el7.x86_64 : Utilities for monitoring process activities
Repo : os
Matched from:
Filename : /usr/bin/ac
# yum -y install psacct
Ubuntu/debian
$ sudo apt-get install acct
或
# apt-get install acctStarting psacct or acct service
默认情况下,psacct服务处于禁用模式,你需要在RHEL/CentOS/Fedora系统下手动开启该服务。请使用下列命令,检查服务状态。
# /etc/init.d/psacct status
Process accounting is disabled.
# chkconfig psacct on
# /etc/init.d/psacct start
Starting process accounting: [ OK ]
显示用户连接时间的统计信息
没有指定参数的ac命令会基于来自当前wtmp文件的用户登录/退出,显示连接时间(小时)的总统计信息。
# ac
total 1141.26
显示每天的用户统计信息
使用ac -d这个命令将输出每天的总登录时间(小时)。
# ac -d
Apr 1 total 2.90
Apr 2 total 17.00
Apr 3 total 4.55
Apr 6 total 1.04
Apr 8 total 1.69
显示每个用户的时间总数
使用ac -p这个命令将显示每个用户的总登录时间(小时)。
# ac -p
root 1136.88
yunwei 4.40
total 1141.28
显示单个用户时间
想得到tecmint这个用户的总登录统计时间(小时),请使用下列命令。
# ac yunwei
total 4.40
显示用户每天的登录时间
下列命令将输出tecmint这个用户的每天总登录时间(小时)。
# ac -d yunwei
Aug 12 total 0.01
Aug 16 total 0.61
Aug 17 total 2.81
Aug 18 total 0.00