脚本名称:clearLog.sh
脚本用途:清理指定天数之前的日志文件
脚本参数:$1:天数
#!/bin/bash logFilePath="/tomcat_path/logs/" logFilePath2="/tomcat_path/logs/" colour=`echo -e "\033[31;40m"` form=`tput sgr0` bold=`tput bold` countSize=0 if [ "$#" != "1" ];then echo "usage:clearLog.sh clear_day" exit 1 fi logFileList=`find $logFilePath $logFilePath2 -name "*.log" -ctime +$1` for i in $logFileList do fileSize=`ls -l $i | awk ‘{print $5}‘` #echo $fileSize countSize=`expr $countSize + $fileSize` rm -fr $i echo "$i 文件已清理" done countSize=`expr $countSize / 1048576` echo "成功清理$colour$bold$1$form天之前的日志,释放空间$colour$bold${countSize}${form}MB"
时间: 2024-11-08 04:37:55