1. 添加bash全局配置文件:bash
cd /etc/profile.dpost
sudo -e vi log_command.shspa
輸入以下內容:debug
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'rest
2. 添加rsyslog配置文件bash.conf:ip
sudo -e /etc/rsyslog.d/bash.confsed
填寫以下內容:配置
local6.* /var/log/commands.logfile
3. 重啓rsyslog服務:bug
sudo 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
/var/log/commands.log{ missingok sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true endscript}