内容一:logrotate 命令的作用
在配置了 logratate 日志之后,想要查看设置的部分配置是否起到了作用,可以使用 logrotate 立刻让日志进行轮转
内容二:logratate 命令的使用
# logrotate -f -v /etc/logrotate.d/syslog
(补充:这里的 /etc/logrotate.d/syslog 是 logrotate 的配置文件)
在配置了 logratate 日志之后,想要查看设置的部分配置是否起到了作用,可以使用 logrotate 立刻让日志进行轮转
# logrotate -f -v /etc/logrotate.d/syslog
(补充:这里的 /etc/logrotate.d/syslog 是 logrotate 的配置文件)
# script <option> <parameter>
1) -a 或者 –append #以追加的方式将记录写入文件
2) -c <command> 或者 –command <command> #运行 script 命令后直接执行 命令,再直接推出 script
3) -e 或者 –return #在 script 命令运行时,显示执行命令的状态返回麻
4) -f 或者 –flush #在 script 命令运行时,只要发生了变化就立刻写入文件
5) –force #写入记录的文件可以是链接
6) -o <size> 或者 –output-limit <size> #限制写入文件的大小, 的单位可以为:KiB (=1024)、KB (=1000)、MiB (10241024)、MB (=10001000)、GiB (=10001000)、TiB (=10001000) 等
7) -q 或者 –quiet #以安静模式运行 script 命令
8) -t[<file>] 或者 –timing[=<file>] #将时间信息输出到标准错误(stderr)或者文件里
9) -V 或者 –version #显示 script 命令的版本
10) -h 或者 –help #显示帮助
# script -a -f command.txt
(补充:这里以追加的形式把用户的所有操作和操作的输出结果写入到 command.txt 文件里)
# exit
(补充:此时在进入 script 命令模式后用户的所有操作和操作的输出结果都已写入到 command.txt 文件里)
# vim /etc/profile
添加以下内容:
......
if [ $UID -ge 0 ]
then
exec -a -f -q /var/log/script-records/$USER-$UID-`date +%Y%m%d`.log
fi
(补充:这里以把所有非 root 用户的操作写入 /var/log/script-records/$USER-$UID-date +%Y%m%d
.log 文件为例)
# source /etc/profile
或者:
# reboot
# mkdir /var/log/script-records
# chmod 750 /var/log/script-records
# /usr/sbin/ausearch --start $(date +\%m/\%d/\%Y -d "-1 month") -i --input-logs | egrep "/test/test.txt.*nametype=CREATE" | awk '{print $2,$3,$6}'
(补充:这里以查看 /test/test.txt 文件有没有被创建为例)
# /usr/sbin/ausearch --start $(date +\%m/\%d/\%Y -d "-1 month") -i --input-logs | egrep "/test/test.txt.*nametype=DELETE" | awk '{print $2,$3,$6}'
(补充:这里以查看 /test/test.txt 文件有没有被删除为例)
# /usr/sbin/ausearch --start $(date +\%m/\%d/\%Y -d "-1 month") -i --input-logs | egrep "/test/test.txt.*nametype=" | awk '{print $2,$3,$6}' | uniq
(补充:这里以查看 /test/test.txt 文件有没有存在过为例)
# cat /var/log/messages | grep -e /usr/sbin/useradd | grep ' ID='
# cat /var/log/messages | grep -e /usr/sbin/userdel | grep ' ID='