天天看點

Nginx日志切割_sedEmail簡單使用

#!/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軟體下載下傳

<a href="http://pan.baidu.com/s/1cEiYZk" target="_blank">http://pan.baidu.com/s/1cEiYZk</a>

# Name:定義郵件發送腳本

# Date:2017-05-12

# 此處定義使用者郵箱名稱如: [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 &gt;/dev/null

     本文轉自812374156 51CTO部落格,原文連結:http://blog.51cto.com/xiong51/1927232,如需轉載請自行聯系原作者

繼續閱讀