windows日誌監控

來源:互聯網
上載者:User

標籤:

  bat指令碼,主要作用,每個五分鐘讀取日文本件中新增內容,進行錯誤賽選,如果有錯誤資訊,將錯誤資訊用郵件發送給管理員。

  其中awk和sed需要手動下載

 

:讀取number.txt文檔,擷取上一次執行時檔案的行數

for /f "delims=" %%f in (number.txt) do (
set a=%%f
)

:讀取新增行,進行ERROR篩選,將賽選資訊匯入err檔案中

D:\tools\awk\awk.exe ‘{print NR" "$0}‘ D:\unitrade\esblls\logs\app.log | D:\tools\sed\sed.exe -n "%a%,$p" | findstr "ERROR" > error_tj.log

:上面這條是本指令碼最費時間的地方,因為當我在awk ‘NR>%A%{PRINT}的時候一直報錯,所以就加了sed賽選起始行

set var="error_tj.log"

:擷取檔案行數,如果為null,則沒有報錯

for /f "delims=" %%i in (%var%) do (

set /a n+=1

)

:::::::::::::: 發送郵件參數設定::::::::::::::
set [email protected]
set user=xxx
set pass=xxx
set to=收件者
set subj=日誌監控
set mail=error_tj.log
set attach=*.jpg
set server=smtp.163.com
set debug=-debug -log blat.log -timestamp

:判斷err檔案中是否有資料,有的話就將err檔案通過郵件發送給管理員

if %n% GTR 0 ( D:\tools\Blat250\full\blat.exe %mail% -to %to% -base64 -charset Gb2312 -subject %subj% -attach %attach% -server %server% -f %from% -u %user% -pw %pass% %debug% )

:擷取最新的行號,並記錄到number.txt檔案中

D:\tools\awk\awk.exe ‘{print NR}‘ D:\unitrade\esblls\logs\app.log | D:\tools\sed\sed.exe -n "$p" > number.txt

windows日誌監控

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.