Solved

Ping IP - Montoring Script cmd

Posted on 2006-11-14
6
8,206 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
6 Comments
 
LVL 18

Expert Comment

by:simsjrg
ID: 17940447
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Even if you have implemented a Mobile Device Management solution company wide, it is a good idea to make sure you are taking into account all of the major risks to your electronic protected health information (ePHI).
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

823 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