日志清理几天前的日志文件

log=/home/hadoop/apache-tomcat-7.0.69/webapps/log

DATETIME=`date -d "2 day ago" "+%Y_%m_%d"`
echo $DATETIME
if [ `date +%w` -eq 1 ]
then
    > $log
fi

echo "=========================================" >> $log
date >> $log
find /home/hadoop/apache-tomcat-7.0.69/webapps -name "$DATETIME*" >> $log
find /home/hadoop/apache-tomcat-7.0.69/webapps -name "$DATETIME*" | xargs -i /bin/rm -f {}

exit 0

cd $(dirname $(readlink -f $0))   用于切到所在目录


你可能感兴趣的:(日志清理几天前的日志文件)