Hello! 欢迎来到小浪云!


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


avatar
小浪云 2024-07-09 39


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


简单的清理脚本如下

#!/bin/bash  cat?/dev/null?>?/var/log/boot.log  cat?/dev/null?>?/var/log/btmp  cat?/dev/null?>?/var/log/cron  cat?/dev/null?>?/var/log/dmesg  cat?/dev/null?>?/var/log/firewalld  cat?/dev/null?>?/var/log/grubby  cat?/dev/null?>?/var/log/lastlog  cat?/dev/null?>?/var/log/mail.info  cat?/dev/null?>?/var/log/maillog  cat?/dev/null?>?/var/log/messages  cat?/dev/null?>?/var/log/secure  cat?/dev/null?>?/var/log/spooler  cat?/dev/null?>?/var/log/syslog  cat?/dev/null?>?/var/log/tallylog  cat?/dev/null?>?/var/log/wpa_supplicant.log  cat?/dev/null?>?/var/log/wtmp  cat?/dev/null?>?/var/log/yum.log  cat?/dev/null?>?/var/log/tuned/tuned.log  rm?-f?/var/log/*-20*?>?/dev/null?2>&1  if?[?-d?"/var/log/anaconda/"?]?;?then  cat?/dev/null?>?/var/log/anaconda/anaconda.log?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/ifcfg.log?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/journal.log?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/packaging.log?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/program.log?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/storage.log?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/syslog?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/anaconda/X.log?>?/dev/null?2>&1  fi  if?[?-d?"/var/log/audit/"?]?;?then  rm?-f?/var/log/audit/audit.log*?>?/dev/null?2>&1  cat?/dev/null?>?/var/log/audit/audit.log?>?/dev/null?2>&1  fi  cat?/dev/null?>?~/.bash_history  cat?/dev/null?>?~/.mysql_history  cat?/dev/null?>?~/.viminfo

最后别忘了额外运行一次 history -c 清理自己的命令列表

相关阅读