Nginx日誌切割 sedEmail簡單使用

2021-09-20 23:04:24 字數 1421 閱讀 4927

#!/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

elif [ ! -d $nginxlogs/$year/$month ];then

fi/bin/mv -i $nginxlogs/xx.xx.log $nginxlogs/$year/$month/xx.xx.log.$datetime

/sbin/service nginx reload

userview=`/bin/awk -f" " 'end' $nginxlogs/$year/$month/preview.access.log.$datetime  | /bin/sort -n | /usr/bin/wc -l`

echo "$datetime 每日ip訪問量為:$userview" >> /tmp/nginxuv.txt

#!/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

nginx日誌切割

web 訪問日誌 access log 記錄了所有外部客戶端對web伺服器的訪問行為,包含了客戶端ip,訪問日期,訪問的url資源,伺服器返回的http狀態碼等重要資訊。一條典型的web訪問日誌如下 規劃 1 要解決問題 2 nignx沒有自動分開檔案儲存日誌的機制。由於nginx它不會幫你自動分檔...

nginx 日誌切割

直接在nginx配置檔案中,配置日誌迴圈,而不需使用logrotate或配置cron任務。需要使用到 time iso8601 內嵌變數來獲取時間。time iso8601格式如下 2015 08 07t18 12 02 02 00。然後使用正規表示式來獲取所需時間的資料。使用下面的 塊 1 2 3...

Nginx日誌切割

編輯指令碼tianshl tianshl nginx vim nginx log division.sh指令碼內容 bin sh 昨天日期 yesterday date v 1d y m d 日誌目錄 log path usr local var log nginx sdk日誌路徑 sdk path...