nginx服务器,从access_log里面提取需要的数据

#!/bin/bash
#author:xxx

start_time=`date +'%d/%b/%Y:%H:00:00' -d '-1 hours'`
end_time=`date +'%d/%b/%Y:%H:59:59' -d '-1 hours'`
#echo $start_time
#echo $end_time

#每小时运行一次
#cat /data/log/nginx/xxx.com | grep 'Baiduspider' | awk '$1 >= "08/Jun/2021:15:00:00" && $1 <= "08/Jun/2021:15:59:59"' >> /data/log/nginx/Baiduspider/xxx.1-` date +%Y-%m-%d-%H -d '- 1 hours'`

#cat /data/log/nginx/xxx.com | grep 'Baiduspider' | awk '$1 >= "$start_time" && $1 <= "$end_time"' >> /data/log/nginx/Baiduspider/xxx.2-` date +%Y-%m-%d-%H -d '- 1 hours'`


awk '{if ($1>=stime && $1<=etime && $14~"Baiduspider") print $0}' stime=$start_time etime=$end_time /data/log/nginx/xxx.com >> /data/log/nginx/Baiduspider/xxx.com-` date +%Y-%m-%d-%H -d '- 1 hours'`

awk '{if ($1>=stime && $1<=etime && $14~"Baiduspider") print $0}' stime=$start_time etime=$end_time /data/log/nginx/xxx.com >> /data/log/nginx/Baiduspider/xxx.com-` date +%Y-%m-%d-%H -d '- 1 hours'`

 

posted @ 2023-09-26 10:06  第一夫人  阅读(82)  评论(0编辑  收藏  举报