#57853 - 2001-08-02 03:50 PM
automatic emails if ping fails
|
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
|
ok i want to set up a batch file that runs via the AT command in NT that pings an IP address and if the outcome of the is an error emails the admin teami can get the email to work by using mapisend.exe from the exchange resource kit i am having problems tho with getting the response from 'ping' please help Pete
|
|
Top
|
|
|
|
#57854 - 2001-08-02 04:05 PM
Re: automatic emails if ping fails
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Peter,Here's one way to do it. There has been much debate on what the find string should be for this technique ... anyone ? (j?): code:
break on $pings = 2 $machine = "shawn"
shell '%comspec% /c ping -n $pings $machine | find /i "received = $pings" >nul 2>nul'
if @error=0 ?"$machine is alive" else ?"$machine is dead or in trouble" endif
exit
-Shawn [ 02 August 2001: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#57857 - 2001-08-02 04:31 PM
Re: automatic emails if ping fails
|
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
|
anyway to do this using normal batch scipts? and not kixtart? just so i can see how it would be done?
|
|
Top
|
|
|
|
#57858 - 2001-08-02 04:39 PM
Re: automatic emails if ping fails
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
ok. I checked this and variable %errorlevel% is set to 1 if find does not find the string.in normal batch file it would be: %comspec% /c ping 292.117.139.29 -n 1 -w 20|find /c "(0% loss)" if "%errorlevel%"=="1" do something... and in kix then: shell '%comspec% /c ping 292.117.139.29 -n 1 -w 20|find /c "(0%'+' loss)"' if @error<>1 do something... try it and say if it works (on my machine it worked fine...) cheers. btw. jochen, try this method to your ping() if you get it work, execution time dries smaller like beer in the sun  [ 02 August 2001: Message edited by: Lonkero ]
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#57859 - 2001-08-02 04:49 PM
Re: automatic emails if ping fails
|
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
|
%comspec% /c ping sh1262 -n 1 -w 20|find /c "(0% loss)" if "%errorlevel%"=="1" do mapisend -u test -p s -r pete.fry -s "ping failed" D:\test-dir>mailto
D:\test-dir>C:\WINNT\system32\cmd.exe /c ping sh1262 -n 1 -w 20 | find /c "(0 loss)" 0 D:\test-dir>if "1" == "1" do mapisend -u test -p s -r pete.fry -s "ping failed" The name specified is not recognized as an internal or external command, operable program or batch file. this is what i get when i run the batch file....... what am i doing wrong?
i'm trying to use the without kix approach atm Pete
|
|
Top
|
|
|
|
#57862 - 2001-08-02 05:09 PM
Re: automatic emails if ping fails
|
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
|
ok here are my results%comspec% /c ping sh1263 -n 1 -w 20|find /c "(0%% loss)" %errorlevel% machine sh1263 doesn't exist and doing a ping sh1263 normally gets requests timed out results in an errorlevel of 1 (which is what i wanted) %comspec% /c ping sh1262 -n 1 -w 20|find /c "(0%% loss)" %errorlevel% machine sh1262 exists but i sell get an errorlevel 1 any ideas? Pete
|
|
Top
|
|
|
|
#57863 - 2001-08-02 05:16 PM
Re: automatic emails if ping fails
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Not so fast Yakamoto  what is '0% loss' ??? Never seen that ! is it 9x ????? In NT a ping reply is for example: Reply from 10.131.96.20: bytes=32 time=30ms TTL=124 i use this in 3.63 (no temp files needed): code:
$machine = "whatever" $timeout = 5000 $pingloop = 6 gosub ping if $reply ; continue else ; loop next endif . . . ing $reply = 0 $c = 0 do shell '%ComSpec /c /e:1024 ping ' + $machine + ' -n 1 -w ' + $timeout + ' | find /C "TTL=" > nul' if @error = 0 $reply = 1 return endif $c = $c + 1 until $c = $pingloop return
J.
[ 02 August 2001: Message edited by: jpols ]
_________________________
|
|
Top
|
|
|
|
#57864 - 2001-08-02 05:18 PM
Re: automatic emails if ping fails
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
My idea is that there is some other failure. I did it like this:code:
%comspec% /c ping pikvalexchange -n 1 -w 20|find /c "(0% loss)" echo "%errorlevel%" %comspec% /c ping pikvalexchange -n 1 -w 20|find /c "(0%% loss)" echo "%errorlevel%"
pikvalexchange = e-mail server and the result was:
code:
C:\kix2k1\rc1>test.batC:\kix2k1\rc1>C:\WINNT\system32\cmd.exe /c ping pikvalexchange -n 1 -w 20 | find /c 0 C:\kix2k1\rc1>echo "1" "1" C:\kix2k1\rc1>C:\WINNT\system32\cmd.exe /c ping pikvalexchange -n 1 -w 20 | find /c 1 C:\kix2k1\rc1>echo "0" "0"
so it worked. take the "-w 20" of and test again. it means that ping does not wait the reply longer than 20ms before quitting with error. if you have slower net you might try to take it of or set to some 100ms. cheers,
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#57866 - 2001-08-02 05:23 PM
Re: automatic emails if ping fails
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
hey jay pols! well, this 0% loss is definitely NOT win9x. but you are right, it can be for some specific producttype examp win2k. my ping gives me (on my win2k wksta):
code:
C:\kix2k1\rc1>C:\WINNT\system32\cmd.exe /c ping pikval_exc -n 1 -w 20Ping-isäntä pikval_exc.pikval.gws.fi [194.197.109.209], 32 tavun paketti: Vastaus isännältä 194.197.109.209: tavuja=32 aika<10 ms TTL=128 Ping-tilastot 194.197.109.209: Paketit: Lähetetty = 1, Vastaanotettu = 1, Kadonnut = 0 (0% loss), Arvioitu kiertoaika millisekunneissa: Minimi = 0 ms, Maksimi = 0 ms, Keskimäärin = 0 ms
so, I thought that loss as only english word might be nice thing to search for.  [ 02 August 2001: Message edited by: Lonkero ]
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#57868 - 2001-08-02 05:32 PM
Re: automatic emails if ping fails
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
like I said - much debate
|
|
Top
|
|
|
|
#57871 - 2001-08-02 05:50 PM
Re: automatic emails if ping fails
|
Peter Fry
Getting the hang of it
Registered: 2001-07-23
Posts: 95
Loc: Bristol UK
|
ok so what should i be doing? using NT and trying to get this working with out kixtart  how do i get the error levels to work? Pete
|
|
Top
|
|
|
|
#57872 - 2001-08-02 06:00 PM
Re: automatic emails if ping fails
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Pete,what ? you don't want to use kix ???? Get off ! No, just kidding ... sample batch I (once) used (called by some other batches (%1 = Computername) code:
@echo off if "%logfile%."=="." SET logfile=CON rem %1: Servername echo ............................. echo Workin' @ %1 SET PINGLOOP=0 :STARTPING if %PINGLOOP% == 9 echo %1: No ping reply >> %logfile% if %PINGLOOP% == 9 GOTO SENDMAIL SET /a PINGLOOP += 1 ping %1 -n 5 -w 5000 | find /C "TTL=" > nul if errorlevel 1 GOTO STARTPING exit :SENDMAIL Your mail command here !
hth
Jochen ps : errrmmm, this was used in a VWAN (Very Wide Area Network) so you might wanna ammend timeout, retries, and loops 
[ 02 August 2001: Message edited by: jpols ] Uups , and not to fergot the calling batch :
code:
@echo off set logfile=%0\..\log\miss.log CALL %0\..\Yourbatchname.CMD Computername1 CALL %0\..\Yourbatchname.CMD Computername2 CALL %0\..\Yourbatchname.CMD Computername3 . .
[ 02 August 2001: Message edited by: jpols ]
_________________________
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|