网站建设资讯

NEWS

网站建设资讯

linux用户操作记录并录入日志

1. 添加bash全局配置文件:
cd /etc/profile.d
vi log_command.sh

输入如下内容:

export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]* 
[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

2. 添加rsyslog配置文件bash.conf:

vi /etc/rsyslog.d/bash.conf

填写如下内容:

local6.*    /var/log/commands.log

3. 重启rsyslog服务:

systemctl restart rsyslog

4. 添加logrotate文件

cd /etc/logrotate.d

vi syslog

添加一行:

/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
/var/log/commands.log #添加这个

{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}

网站栏目:linux用户操作记录并录入日志
文章出自:http://njwzjz.com/article/jdshps.html