#!/bin/bash
#
# Name:此脚本做为切割nginx每日日志使用
# Version Number:1.1
# Language:bash shell
# Date:2017-05-11
# Author:xiong
nginxlogs=/usr/share/nginx/log
datetime=`date ‘+%Y-%m-%d‘ -d ‘-1 day‘`
year=`date +%Y`
month=`date +%m`
if [ ! -d $nginxlogs/$year ];then
mkdir $year
elif [ ! -d $nginxlogs/$year/$month ];then
mkdir $nginxlogs/$year/$month
fi
/bin/mv -i $nginxlogs/xx.xx.log $nginxlogs/$year/$month/xx.xx.log.$datetime
/sbin/service nginx reload
userview=`/bin/awk -F" " ‘{uv[$1]++}END{for (u in uv) print u}‘ $nginxlogs/$year/$month/preview.access.log.$datetime | /bin/sort -n | /usr/bin/wc -l`
echo "$datetime 每日IP访问量为:$userview" >> /tmp/nginxuv.txt
# sendEmail软件下载
http://pan.baidu.com/s/1cEiYZk
#!/bin/bash
#
# Name:定义邮件发送脚本
# Version Number:1.1
# Language:bash shell
# Date:2017-05-12
# Author:xiong
# 此处定义用户邮箱名称如: [email protected]
[email protected]
# 此处定义用户邮箱密码
userpass=xxqq
# 此处定义要发送哪个用户如 a.com发给b.com 这就定义b.com
senduser="[email protected] "
# 此处定义smtp地址 如smtp.qiye.163.com:25 必须加端口号
smtpaddess=smtp.qiye.163.com:25
# 此处定义邮件主题
subject="test信息"
# 此处定义邮件信息
message=`tail -n 1 /tmp/nginxuv.txt`
/usr/local/bin/sendEmail -f $username -t $senduser -s $smtpaddess -u $subject -o tls=auto -o message-content-type=html -o message-charset=utf8 -xu $username -xp $userpass -m $message >/dev/null