My Monitoring is not working (ping and portqry)

  • Thread starter Thread starter Gill Bates
  • Start date Start date
G

Gill Bates

I'm tryingo to test a remote system by ping and portqry to warn via net
send, problems
My Batchs is not working. Why?


PINGMON.BAT
==================================
@echo off
cls
echo.
echo.
echo Definindo variaveis de ambiente
set TARGET=192.168.100.88
echo.
echo.
echo Apagando arquivo de registro
del c:\PINGMON.LOG
echo.
echo.
echo Testando conectividade
ping %TARGET% -l 1 -n 1 > c:\PINGMON.LOG
find "Reply from" c:\PINGMON.LOG
if not errorlevel 0 goto ERRO
goto END

:ERRO
echo.
echo.
NET SEND DSK50 "Error"
:END

==================================






PORTMON.BAT
==================================
@echo off
cls
portqry -n 192.168.100.1 -p tcp -e 80 -q
if errorlevel 0 goto LISTENING
if errorlevel 1 goto NOT_LISTENING
if errorlevel 2 goto LISTEN_FILTER
goto END

:LISTENING
echo.
echo.
echo OUVINDO
goto END


:NOT_LISTENING
echo.
echo.
echo NAO OUVINDO
goto END


:LISTEN_FILTER
echo.
echo.
echo FILTRADA ou OUVINDO
goto END


goto END


:END
==================================
 
Hi,

Gill said:
I'm tryingo to test a remote system by ping and portqry to warn via
net send, problems
My Batchs is not working. Why?

you did not write anything about the operating systems, you are using.
What lets you assume, that the batch is not working?

May be the clients simply don't respond - Windows Firewall enabled?
Best greetings from Germany
Olaf.
 
The routine is entering on wrong GOTOs
If i ping a valid/invalid hostname, the answer is the same
If i try to test via portqry a valid/invalid port the answer is always the
same

i think the errlevel routine is wrong
 
Gill said:
I'm tryingo to test a remote system by ping and portqry to warn via net
send, problems
My Batchs is not working. Why?
Because you are misunderstanding how errorlevel works.

<cite from a recent posting in amb from Norman L Deforest>
COMMAND.COM's "If ErrorLevel n" (where 'n' is a number from 0 to 255) can
be translated as "If ErrorLevel is greater than or equal to n".
Obviously, "If ErrorLevel 0" is always true.

To check for different errorlevels, check the higher numbers first.
</cite>

If you pipe the output no temp file necessary.
PINGMON.BAT
==================================
@echo off
cls
echo.
echo.
echo Definindo variaveis de ambiente
set TARGET=192.168.100.88
echo.
echo.
echo Apagando arquivo de registro
echo.
echo.
echo Testando conectividade
ping %TARGET% -l 1 -n 1 | find "Reply from"
if errorlevel 1 goto ERRO
goto END

:ERRO
echo.
echo.
NET SEND DSK50 "Error"
:END
==================================

PORTMON.BAT
==================================
@echo off
cls
portqry -n 192.168.100.1 -p tcp -e 80 -q
echo.
echo.
if errorlevel 2 echo FILTRADA ou OUVINDO &goto END
if errorlevel 1 echo NOA OUVINDO &goto END
if errorlevel 0 echo OUVINDO &goto END
:END
==================================

HTH
 
OK, but i wanna try to catch ANY error, so catching only errorlevel 1 (and
not errorlevel 2 and so on) will do my mon app less effective
 
Gill said:
OK, but i wanna try to catch ANY error, so catching only errorlevel 1 (and
not errorlevel 2 and so on) will do my mon app less effective

Please reread this until you understand.

if errorlevel 1 catches *all* errorlveles greater or equal 1.
If you want to act on specific levels you have to check in descending
order.

HTH
 
Gill said:
OK, but i wanna try to catch ANY error, so catching only errorlevel 1 (and
not errorlevel 2 and so on) will do my mon app less effective
BTW if you read the help you will discover that in w2k/xp (not shure
about nt) there is also an *environment variable* %errorlevel% which you
can check against a single number.

if "%errorlevel%" EQU "2" echo exactly errorlevel 2

HTH
 
Back
Top