Windows Service monitoring and mail reporting Scripts

Create following two files and modify accordingly as per your requirement. Create a scheduled batch file to execute.

File name Service Test.bat
Set Location as C:\
---------
c:\
date /t >C:\PortsReport.txt
time /t >>C:\PortsReport.txt
portQry -n Server name -e 25 >>C:\PortsReport.txt
portQry -n Server name -e 110 >>C:\PortsReport.txt
portQry -n Server name -e 80 >>C:\PortsReport.txt
set /A STATUS = 0For /F " eol=; delims=: tokens=3" %%I in (' Find /I /C "NOT LISTENING"C:\PortsReport.txt') Do Set status=%%I
if /I %STATUS% gtr 0 cscript C:\Errormail.vbs
-----

File Name ErrorMail.vbs
Set Location as C:\
----
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Server Protocol Status Report"
objMessage.From = ""
objMessage.To = ""
objMessage।TextBody = ""
objMessage.AddAttachment "C:\PortsReport.txt"
objMessage.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP ServerobjMessage.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
'Server port (typically 25)objMessage.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
--------

Comments

Popular posts from this blog

LDAP Queries

Exchange 2007 Powershell

Delete Media Files