squid 日志
#!/bin/bash
set -e
#此脚本放在日志所在目录
#年/月(两位)/日(两位)/主机名/servicename/filename
#绝对路径:/data/log1/2010/08/05/$HOSTNAME/$SERVICENAME/$FILENAME
#现在服务nginx,tomcat,squid
#for squid
#假定目录:/data/logs/squid
YESTERDAY=`date -d '1 day ago' +%Y%m%d`
YEAR=`date -d '1 day ago' +%Y`;
MONTH=`date -d '1 day ago' +%m`;
DAY=`date -d '1 day ago' +%d`;
HOSTNAME=`echo $HOSTNAME`
SERVICENAME=`pwd |awk -F/ '{print $4}'`
cd /data/logs/squid;
/usr/local/squid/sbin/squid -k rotate
for FILELOG in `ls |grep .0`
do
[[ -f "$FILELOG" ]] && mv $FILELOG $FILELOG.$YESTERDAY && gzip -9 $FILELOG.$YESTERDAY;
done
/bin/mkdir -p ./$YEAR/$MONTH/$DAY/$HOSTNAME/$SERVICENAME
/bin/mv *.gz ./$YEAR/$MONTH/$DAY/$HOSTNAME/$SERVICENAME
/usr/bin/rsync -aR $YEAR/ backup@192.168.200.11::log1 --password-file=/etc/rsync.pass
/bin/rm -rf ./$YEAR;
#下面一行放在crontab中,计划执行任务
#1 0 * * * root /data/logs/squid/sqlogrotate.sh
阅读(732) | 评论(0) | 转发(0) |