Last active
May 7, 2018 09:01
-
-
Save the-takeo/f2a02343ada1d8585dec5a4b0e79ef6e to your computer and use it in GitHub Desktop.
CheckDeadLock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET FLD=%~dp0 | |
SET TXT_DEADLOCK=DeadLock.txt | |
If not Exist %FLD% mkdir %FLD% | |
del %FLD%\%TXT_DEADLOCK% | |
bcp "SELECT * FROM sys.fn_xe_file_target_read_file('C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\DeadLock*.xel', 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\DeadLock*.xem', null, null)" queryout "%FLD%\%TXT_DEADLOCK%" -T -c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET FLD=%~dp0 | |
SET ROWS=0 | |
Call %FLD%GetDeadLock.bat | |
for /f "delims=" %%a in (%FLD%\DeadLock.txt) do ( | |
set /a ROWS+=1 | |
) | |
if %ROWS% equ 0 EXIT /b 0 | |
Cscript.exe %FLD%\SendMail.vbs" | |
sqlcmd -E -S localhost -Q "ALTER EVENT SESSION [DeadLockLog] ON SERVER STATE=STOP" | |
move "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\DeadLock*.xel" "C:\Users\Administrator\Documents\DailyBatch\CheckDeadLock\oldLog" | |
move "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\DeadLock*.xem" "C:\Users\Administrator\Documents\DailyBatch\CheckDeadLock\oldLog" | |
sqlcmd -E -S localhost -Q "ALTER EVENT SESSION [DeadLockLog] ON SERVER STATE=START" | |
EXIT /b 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Dim mFrom | |
Dim mTo | |
Dim SmtpSvr | |
Dim Attachment1 | |
mFrom = "from@dummy.com" | |
mTo = "to@dummy.com" | |
SmtpSvr = "localhost" | |
Attachment1 = "C:\Users\Administrator\CheckDeadLock\DeadLock.txt" | |
'メイン(変更不要)-------------------- | |
Dim Subject 'メール題 | |
Dim TextBody 'メール本文 | |
Subject = "デッドロック情報"'WScript.Arguments.Item(0) | |
TextBody = "デッドロック情報です。詳細は添付ファイルをご参照ください。"' WScript.Arguments.Item(1) | |
Dim oMsg | |
Set oMsg = CreateObject("CDO.Message") | |
oMsg.From = mFrom | |
oMsg.To = mTo | |
oMsg.Subject = Subject | |
oMsg.TextBody = TextBody | |
oMsg.AddAttachment Attachment1 | |
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/" + "sendusing")= 2 | |
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/" + "smtpserver")= SmtpSvr | |
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/" + "smtpserverport")=25 | |
oMsg.Configuration.Fields.Update | |
oMsg.Send |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment