Link to home
Start Free TrialLog in
Avatar of ThinkPaper
ThinkPaperFlag for United States of America

asked on

Ping IP - Montoring Script cmd

Hey Experts -
I am trying to create a script that will continuously ping several IP addresses listed in a text file. I have found a script that worked and tried modifying it so it would continue to ping at certain intervals, however I don't think I have the code right. I want it to ping say.. every 5 minutes or something to that effect - not every second. Also I think my loop is wrong as it is only pinging the first IP in my textfile and not the others. (It works fine however when I modify it for a one time ping.) Can someone take a look at this and help?
This is my first time really scripting something like this.. but I had thought that the -W part meant the pause between pings - but it didn't seem to slow down one bit. If anyone could help explain the -N and -W it would really help.
Note: I don't want to use outside resources as it would mean me having to jump thru hoops to get software approved and all that - for security and simplicity issues - scripting is my best option.
Could anyone also tell me if this method would effect the performance of the server or my machine?
Thanks

@echo off

if exist error.txt del error.txt >NUL

:pingtest

for /f "delims=" %%a in ('type myIP.TXT') do call :PROCESS %%a

goto :pingtest

:PROCESS

ping %1 -n 1 -w 20000 >NUL

if ERRORLEVEL 1 goto IPERROR

echo IP: %1 worked  
goto :pingtest

:IPERROR

echo IP: %1 is down at %time% >> error.txt
Avatar of simsjrg
simsjrg
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ThinkPaper

ASKER

Thanks for the quick response. It works great. I modified it a little bit to output on command line when it failed.

So on the command line it only printed when it couldn't ping an IP. And any errors went into the error.txt

A couple questions - any reason why this method would not be a good idea? I'm wondering if I would be pinging the server too much or taking up too much resources or whatever. (I'm not a network person - I'm just helping someone automate this task for them.)

And is there a better way of doing this (like making an alert box pop up when an IP fails)?

Thanks!
"any reason why this method would not be a good idea? "

Hmm - I'd say likely not, but keep an eye on it, just in case...  If things start to degrade, you'll know soon enough.
The pinging localhost (the loopback) doesn't 'go' anywhere, so that's not even on your network.  It may take a minute amount of local resources, but it's unlikely to cause any problem.  Now depending on your operating system and/or availability to download free tools, there is a utility called sleep (just type sleep at the command prompt to see if you have it already) that essentially pauses execution for you.  It's probably not any more/less of a resource usage problem, it just 'looks' cleaner when using it.

"And is there a better way of doing this (like making an alert box pop up when an IP fails)?"

There are several monitoring tools out there...snmp traps, tivoli, netview, etc that serve a similar purpose (with added support features).  
Avatar of dlangr
dlangr

don't forget:

bigsister http://www.bigsister.ch/bigsister.html (free, runs on windows, linux and probably others)
bigbrother http://www.bb4.org/ (a free and a commercial version)


ok thanks guys =)
i'll keep using this until I see any issues.