我的环境是:
#!/bin/bash -x #used for zip nginx log logs_path="/usr/local/nginx/logs" temp_path="/nginx_log_temp" YESTERDAY=`date +%Y%m%d -d "yesterday" ` test -e $temp_path || mkdir $temp_path rm -rf $temp_path/* cd ${logs_path}/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/ for i in domain1 domain2 domain3 do if [ `du $i.log.$YESTERDAY|awk '{if($1>8208){print $NF}}'` ];then tar -czf $i.log.$YESTERDAY.tar.gz $i.log.$YESTERDAY mv $i.log.$YESTERDAY.tar.gz $temp_path fi done
#!/bin/bash -x #used for donwload logfile down_tmp="/tmp/down_tmp" test -e $down_tmp || mkdir $down_tmp for i in domain1 domain2 domain3 do test -e /tmp/$i || mkdir /tmp/$i done for i in a.a.a.a b.b.b.b c.c.c.c d.d.d.d do cd /tmp/down_tmp/$i test -e /tmp/unzip_tmp/$i || mkdir -p /tmp/unzip_tmp/$i sftp root@$i:/nginx_log_temp/ << EOF get *.tar.gz exit EOF for a in ` ls -l | grep .tar.gz | awk '{print $NF}'` do tar -xzf $a -C /tmp/unzip_tmp/$i done done
[root@localhost ~]# crontab -l 0 9 * * * /bin/bash /root/sftp_autodown_nginx_log > /dev/null 30 9 * * * /usr/local/awstats/tools/awstats_updateall.pl now > /dev/null