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

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.......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.