定时统计nginx访问日志

统计前一天nginx的访问记录

#!/bin/bash
date=`date -d "1 day ago" +%Y%m%d`                                                     #前一天
#date=`date +%Y-%m-%d`
log_dir=/var/log/nginx                                                                 #日志目录
f_log=/var/log/nginx/access.log-$date.gz                                               #日志文件
if [ -f "$f_log" ]; then
        if [ ! -f "$log_dir/access_log/$date.log" ]; then
                `touch $log_dir/access_log/$date.log`
        fi
        zcat $f_log |awk '{print $1}' |sort |uniq -c |sort -n > $log_dir/access_log/$date.log    
#统计前一天的访问记录,并放在指定的文件中
else if [ ! -f "$log_dir/access_log/$date.log" ]; then touch $log_dir/access_log/$date.log fi echo "$f_log doesn't exit" > $log_dir/access_log/$date.log fi
  • 定时每天凌晨一点执行

猜你喜欢

转载自www.cnblogs.com/psc0218/p/12750514.html