Ping server & Send mail

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Fire cat
Posts: 2
Joined: 12 Jul 2010 07:38

Ping server & Send mail

#1 Post by Fire cat » 12 Jul 2010 07:44

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

Fire cat
Posts: 2
Joined: 12 Jul 2010 07:38

Re: Ping server & Send mail

#2 Post by Fire cat » 12 Jul 2010 07:47

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%?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Ping server & Send mail

#3 Post by aGerman » 12 Jul 2010 12:22

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Ping server & Send mail

#4 Post by avery_larry » 12 Jul 2010 14:06

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

Really 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

Post Reply