Page 1 of 1
Ping server & Send mail
Posted: 12 Jul 2010 07:44
by Fire cat
Hey guys! Need help here!
Ok, so I've got this server. I need a batch file that will ping it, and if the server doesn't respond it sends me an email.
Anyone got ideas? I'm stuck! And I need this for next week!
Pls help!
FC
Re: Ping server & Send mail
Posted: 12 Jul 2010 07:47
by Fire cat
I know I need to use "ping 192.xxx.xxx.xxx 458" to ping the server, but then? How to send an email if packet loss is at 100%?
Re: Ping server & Send mail
Posted: 12 Jul 2010 12:22
by aGerman
You can't send an email by native batch. You could use
blat, but you must have access to an email server.
Code: Select all
@echo off &setlocal
ping 192.xxx.xxx.xxx >nul && goto :eof
:: your blat stuff here
Regards
aGerman
Re: Ping server & Send mail
Posted: 12 Jul 2010 14:06
by avery_larry
If for some reason you *don't* need this to be native dos, then I suggest the hostmonitor program:
http://www.ks-soft.net/hostmon.eng/index.htmReally nice monitoring program.
Otherwise, to expand on what aGerman said -- I have a file I've created called "pingtest", which doesn't send an email but could easily be adapted:
Code: Select all
@echo off
setlocal enabledelayedexpansion
set array=-1
ping -n 1 -w 1000 %1|find /i "ttl=">nul
if errorlevel 1 goto down
:up
set /a array+=1
set header%array%=%date% %time% %1 Ping is up.
:uploop
cls
for /l %%a in (0,1,%array%) do echo !header%%a!
echo.
ping -n 1 -w 1000 %1|find /i "ttl=" || ping -n 1 -w 1000 %1|find /i "ttl=" || goto :down
if errorlevel 1 goto down
ping -n 3 -w 800 127.0.0.1 >nul 2>&1
goto uploop
:down
set /a array+=1
set header%array%=%date% %time% %1 Ping is down.
:downloop
cls
for /l %%a in (0,1,%array%) do echo !header%%a!
echo.
ping -n 1 -w 1000 %1|find /i "ttl=" && goto up
ping -n 3 -w 800 127.0.0.1 >nul 2>&1
goto downloop