我心如烟卸 发表于 2024-9-11 15:05:53

云服务器一个简单的清理 Linux 日志的脚本

一台服务器运行一段时间后,系统就会产生各种各样的日志,而这些日志其实暴漏了系统的很多信息,这时候就需要定期清理使用痕迹


简单的清理脚本如下
#!/bin/bashcat?/dev/null?>?/var/log/boot.logcat?/dev/null?>?/var/log/btmpcat?/dev/null?>?/var/log/croncat?/dev/null?>?/var/log/dmesgcat?/dev/null?>?/var/log/firewalldcat?/dev/null?>?/var/log/grubbycat?/dev/null?>?/var/log/lastlogcat?/dev/null?>?/var/log/mail.infocat?/dev/null?>?/var/log/maillogcat?/dev/null?>?/var/log/messagescat?/dev/null?>?/var/log/securecat?/dev/null?>?/var/log/spoolercat?/dev/null?>?/var/log/syslogcat?/dev/null?>?/var/log/tallylogcat?/dev/null?>?/var/log/wpa_supplicant.logcat?/dev/null?>?/var/log/wtmpcat?/dev/null?>?/var/log/yum.logcat?/dev/null?>?/var/log/tuned/tuned.logrm?-f?/var/log/*-20*?>?/dev/null?2>&1if?[?-d?"/var/log/anaconda/"?]?;?thencat?/dev/null?>?/var/log/anaconda/anaconda.log?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/ifcfg.log?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/journal.log?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/packaging.log?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/program.log?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/storage.log?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/syslog?>?/dev/null?2>&1cat?/dev/null?>?/var/log/anaconda/X.log?>?/dev/null?2>&1fiif?[?-d?"/var/log/audit/"?]?;?thenrm?-f?/var/log/audit/audit.log*?>?/dev/null?2>&1cat?/dev/null?>?/var/log/audit/audit.log?>?/dev/null?2>&1ficat?/dev/null?>?~/.bash_historycat?/dev/null?>?~/.mysql_historycat?/dev/null?>?~/.viminfo
最后别忘了额外运行一次 history -c 清理自己的命令列表
页: [1]
查看完整版本: 云服务器一个简单的清理 Linux 日志的脚本