?
Solved

Ping IP - Montoring Script cmd

Posted on 2006-11-14
6
Medium Priority
?
8,259 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:ThinkPaper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Expert Comment

by:simsjrg
ID: 17940447
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 17940458
Try this and post your results please...comments are posted first:

1- specify path of myIP.txt (don't need 'type')
2- ping localhost is an internal 'trick' to wait a approximate amount of seconds
3- removed your goto :pingtest inside of process -unneeded


@echo off
if exist error.txt del error.txt >NUL
:pingtest
for /f "delims=" %%a in (c:\folder\myIP.txt) do call :PROCESS %%a
::wait 300 seconds before continuing
ping localhost -n 300 > NUL
goto :pingtest

:PROCESS
ping %1 -n 1 >NUL
if ERRORLEVEL 1 goto IPERROR
echo IP: %1 worked  
goto :eof

:IPERROR
echo IP: %1 is down at %time% >> error.txt
0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 17940917
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!
0
Limited time offer using promo code EXPERTS25

Designed with a wealth of functionality and convenience, ATEN's new Thunderbolt™ 2 Sharing Switch takes your Thunderbolt setup to the next level. Now through August 31, 2017, Experts Exchange members get 25% off the US7220 on the ATEN USA eShop using promo code EXPERTS25.

 
LVL 67

Expert Comment

by:sirbounty
ID: 17941065
"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).  
0
 
LVL 7

Expert Comment

by:dlangr
ID: 17941143
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)


0
 
LVL 16

Author Comment

by:ThinkPaper
ID: 17941363
ok thanks guys =)
i'll keep using this until I see any issues.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question