前些日子,系統上線了,發現tomcat 下的日志增長得挺快的,寫了個腳本清除n天以前的日志
web_def_tomcat_log_path=/Application/tomcat/log
$web_def_tomcat_log_expire_days=7
if [ "$web_def_tomcat_log_expire_days" -gt 0 ]
then
echo "find $web_def_tomcat_log_path -follow -mtime +$web_def_tomcat_log_expire_days -name '*.log' -exec rm -f {} \;"
find $web_def_tomcat_log_path -follow -mtime +$web_def_tomcat_log_expire_days -name '*.log' -exec rm -f {} \;
fi
由于web的mysql下面挂的同步太多了,每天産生1-2G的mysql-bin檔案,是以也寫了個清除mysql-bin的檔案,這個檔案會至少保留最新的一個mysql-bin.0*檔案
web_def_host="1.2.3.4" #mysql的ip
web_def_port=3306 #mysql的端口
web_def_username="tester" #mysql的使用者
web_def_password="123" #mysql的密碼
web_def_mysql_expire_logs_days=7 #删除7天以前的mysql-bin,但是最後至少保留一個檔案
mysql_exe="mysql -h $web_def_host -P $web_def_port -u $web_def_username --password=$web_def_password -e "
if [ "$web_def_mysql_expire_logs_days" -gt 0 ]
#擷取n天以前被修改的mysql-bin檔案,
logFileName=`find $web_def_mysql_data_path -follow -atime -$web_def_mysql_expire_logs_days -name 'mysql-bin.0*' |sort|head -1`
if [ "$logFileName" != "" ]
logFileName=`basename $logFileName`
echo $mysql_exe "\"PURGE MASTER LOGS TO '$logFileName'\""
$mysql_exe "PURGE MASTER LOGS TO '$logFileName'";
fi
本文轉自yifangyou 51CTO部落格,原文連結:http://blog.51cto.com/yifangyou/610317,如需轉載請自行聯系原作者