统计前一天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
- 定时每天凌晨一点执行

【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!