温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-13 23:14:02 来源:网络 阅读:801 作者:wx5834f0f0d5480 栏目:系统运维
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
}
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI