1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| #!/bin/sh
# 获取当前日期 beg_time=$(date -d "-7 day" +%d/%b/%Y) end_time=$(date +%d/%b/%Y) sum_cont=0
# 文件路径 FILE="/home/script/nginx_access_wc.log"
# 读取文件的最后一行 last_line=$(tail -n 1 "$FILE")
# 提取最后一行中的数字 number=$(echo "$last_line" |awk '{print $2}' | grep -oE '[0-9]+')
echo "-----------------------------------------"
# 用户数据 user_count=`/usr/bin/mysql -h 192.168.1.xx -uxxxx -pxxxx@xxxx! -e "select * from store.usertbl;" |wc -l`
# 本周新增用户 start_time=$(date -d "-7 day" +"%Y-%m-%d 00:00:00") stop_time=$(date -d "-1 day" +"%Y-%m-%d 23:59:59") add_user_count=$(/usr/bin/mysqlbinlog --start-datetime="${start_time}" --stop-datetime="${stop_time}" /var/lib/mysql/binlog.000001 -vv | grep -w "### INSERT INTO" | wc -l)
# 新增用户的日期 add_user_time=$(/usr/bin/mysqlbinlog --start-datetime="${start_time}" --stop-datetime="${stop_time}" /var/lib/mysql/binlog.000001 -vv |grep -w "Write_rows" |awk '{print $1}' |sed 's/#/20/g' |sed ':a;N;$!ba;s/\n/ /g')
# 循环输出一周内的日期 for ((i=7; i>0; i--)) do current_date=$(date -d "-$i day" +%d/%b/%Y) day_count=$(grep -E "GET / HTTP/1.1" /usr/local/nginx-1.20.2/logs/access.log |grep $current_date |awk -F ":" '{print $2":"$3":"$4}'|awk '$1>="00:00:00" && $1<="23:59:59"' |wc -l) sum_cont=$(($sum_cont + $day_count)) done
# 总浏览量 ALL_COUNT=$((${number} + ${sum_cont}))
printf "本次统计开始时间: $(date -d "-7 day" +%Y-%m-%d) 00:00:00\n" printf "本次统计结束时间: $(date -d "-1 day" +%Y-%m-%d) 23:59:59\n" printf "本周新增用户信息数: ${add_user_count}\n" printf "本周新增用户日期: ${add_user_time}\n" printf "用户信息收集总数据: $((${user_count}-3))\n" printf "当周浏览量(上周日[00:00:00]到本周六[23:59:59]): ${sum_cont}\n" printf "总浏览量(截止到本周六[23:59:59]): ${ALL_COUNT}\n" #printf "本周新增用户数据:\n${add_user_data}\n"
|