#!/bin/bash
#本脚本用来统计特定时间段内,独立访问的用户数量
# 清空之前的记录
echo ''> /tmp/tmp.txt
echo ''>/tmp/tongji
#设置语言环境,换取需要的日月的格式
LANG=en_US.UTF-8
mon=`date +%B --date="-1 day"`
month=${mon:0:3}
date=`date +%d --date="-1 day"`
year=`date +%Y`
#变量的带入
first="[$date/$month/$year:00:00:00"
last="[$date/$month/$year:24:00:00"
for s in `ls | grep -v error.log | grep -v test.sh | grep -v access1.log | grep -v tongji.sh`
do
cat $s | awk -v First="$first" -v Last="$last" '$4 >=First && $4 <=Last' | awk '{print $1}' >>/tmp/tmp.txt
name=`echo $s | cut -d\. -f 1`
echo -n "$name访问量为 :" >>/tmp/tongji
cat $s | awk -v First="$first" -v Last="$last" '$4 >=First && $4 <=Last' | awk '{print $1}'|sort | uniq -c |wc -l >>/tmp/tongji
done
echo -n "总访问量为:">>/tmp/tongji
# 去重ip,获取所有的访问量
cat /tmp/tmp.txt | sort | uniq -c |wc -l>>/tmp/tongji
# 安装配置邮件
if [ `rpm -qa mailx|wc -l` == 0 ]
then
yum install mailx -y
cat >>/etc/mail.rc<EOF
set from="*****@163.com"
set smtp=smtp.163.com
set smtp-auth-user=****@163.com
set smtp-auth-password=*****
set smtp-auth=login
EOF
fi
# 发送邮件配置
cat /tmp/tongji | mailx -s "移动线路 nginx访问量 " ssg@beiyang.com 122121@139.com
网友评论