日志处理1
时间:2010-08-09 来源:chibiaowu
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/ [email protected]::log1 --password-file=/etc/rsync.pass
/bin/rm -rf ./$YEAR;
#下面一行放在crontab中,计划执行任务
#1 0 * * * root /data/logs/squid/sqlogrotate.sh
#!/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/ [email protected]::log1 --password-file=/etc/rsync.pass
/bin/rm -rf ./$YEAR;
#下面一行放在crontab中,计划执行任务
#1 0 * * * root /data/logs/squid/sqlogrotate.sh
相关阅读 更多 +