CentOS Stream 8
Sponsored Link

Psacct : プロセスアカウンティングを有効にする2021/03/08

 
psacct をインストールしてプロセスアカウンティングを有効にします。
ユーザー自身が自由に編集・削除可能な history とは別で、全てのコマンド履歴を残すことができます。
[1] psacct をインストールして起動します。
[root@dlp ~]#
dnf -y install psacct
[root@dlp ~]#
systemctl enable --now psacct
[2] コマンド履歴のログはバイナリファイルとなっているので、専用のコマンドで内容を出力します。
[root@dlp ~]#
lastcomm

su               S     root     ttyS0      0.01 secs Sun Mar  7 13:04
bash             S     cent     ttyS0      0.02 secs Sun Mar  7 13:04
su               S     cent     ttyS0      0.01 secs Sun Mar  7 13:05
.....
.....
systemd-tty-ask  S     root     ttyS0      0.00 secs Sun Mar  7 13:04
systemd-cgroups        root     __         0.00 secs Sun Mar  7 13:04
accton           S     root     __         0.00 secs Sun Mar  7 13:04

# ユーザーを指定する場合は以下

[root@dlp ~]#
lastcomm --user cent

bash             S     cent     ttyS0      0.02 secs Sun Mar  7 13:04
su               S     cent     ttyS0      0.01 secs Sun Mar  7 13:05
systemctl              cent     ttyS0      0.00 secs Sun Mar  7 13:05
.....
.....
hostname               cent     ttyS0      0.00 secs Sun Mar  7 13:04
bash              F    cent     ttyS0      0.00 secs Sun Mar  7 13:04
id                     cent     ttyS0      0.00 secs Sun Mar  7 13:04

# コマンドを指定する場合は以下

[root@dlp ~]#
lastcomm --command su

su               S     root     ttyS0      0.01 secs Sun Mar  7 13:04
su               S     cent     ttyS0      0.01 secs Sun Mar  7 13:05
su               S     cent     ttyS0      0.01 secs Sun Mar  7 13:05
[3] [/var/log/wtmp] のログを基に、ユーザーのログイン時間を出力するには、付属の [ac] コマンドを使用します。
# 日毎のトータル表示

[root@dlp ~]#
ac -d

.....
.....
Feb 18  total        0.00
Feb 24  total        0.21
Mar  4  total        0.01
Today   total        3.68

# ユーザー毎のトータル表示

[root@dlp ~]#
ac -p

        cent                                 0.26
        root                                 3.63
        redhat                               0.01
        total        3.90

# 日毎 + ユーザー毎

[root@dlp ~]#
ac -d -p

.....
.....
Feb 18  total        0.00
        root                                 0.21
Feb 24  total        0.21
        root                                 0.01
Mar  4  total        0.01
        cent                                 0.26
        root                                 3.41
        redhat                               0.01
Today   total        3.69

# エラーを表示

[root@dlp ~]#
ac -d --complain

/var/log/wtmp:1: problem: time warp (Thu Jan  1 09:00:00 1970 -> Thu Feb 18 15:51:53 2021)
/var/log/wtmp:8: problem: missing login record for `tty1'
Feb 18  total        0.00
/var/log/wtmp:19: problem: missing login record for `tty1'
/var/log/wtmp:28: problem: missing login record for `tty1'
/var/log/wtmp:38: problem: missing login record for `tty1'
Feb 24  total        0.21
/var/log/wtmp:48: problem: missing login record for `tty1'
Mar  4  total        0.01
.....
.....
/var/log/wtmp:194: problem: missing login record for `tty1'
/var/log/wtmp:207: problem: missing login record for `ttyS0'
Today   total        3.70
関連コンテンツ