0

Hello All,

I have created a batch file on a Windows XP PC, pings over 10 servers 24x7x356 and redirects the error messages <100% loss> to an output file which is a notepad.

Now I would like to add code to this bacth file that sends e- mail to me and number of other stating error <servers not reached > or all is fine.

I am new to writing code creating batch file and would be thankfull if anyone in the forum can help me.

Thanks and regards

Mah1

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by CWorl
0

You need a command line email client. I use postie; found here: http://www.infradig.com/price.html.

The batch file below will email you when a server is down and will not email you again until it comes back up...

I created a directory 'c:\monitor' and placed 'iplist.txt' and 'monitor.bat' in it.

iplist.txt contains (as many as you want, one per line, no spaces):
ipaddress,servername
ipaddress,servername

monitor.bat contains (minus the CODE tags):

@echo off
echo.
echo Running Ping Monitor... Do not close.
echo.
for /f "tokens=*" %%i in ('date /t') do (
	set mydate=%%i
)

for /f "tokens=*" %%i in ('time /t') do (
	set mytime=%%i
)

for /f "tokens=1,2 delims=," %%a in (iplist.txt) do (
	cls
	echo Running Ping Monitor... Do not close.
	echo.
	echo Currently testing %%b
	echo.
	ping %%a >round2.txt
	findstr Reply round2.txt
	if errorlevel==1 (
		if not exist %%b.txt (
			echo %mydate%, %mytime%, %%b Down>>%%b.txt
			postie -host:[emailserver] -from:[email@domain.com] -to:[email@domain.com] -s:"Server %%b Down" -msg:"%mydate%, %mytime%, Cannot reach %%b - %%a"
		)
	) else (
		if exist %%b.txt (
			postie -host:[emailserver] -from:[email@domain.com] -to:[email@domain.com] -s:"Server %%b Back UP" -msg:"%mydate%, %mytime%, %%b - %%a is back up!"
			del -f %%b.txt
		)
	)
del -f round2.txt
)

_end

note you need to replace anything in [] on the postie lines with your info...

Finally I created a scheduled task to run it every few minutes.

Works for me; hope it helps you.......

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.