[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Ping Script & automatic trace route

Posted on 2011-02-16
8
Medium Priority
?
802 Views
Last Modified: 2013-12-07
Hi,

I have a number of devices that loose connectivity, they are connected through various ways and 3rd party clouds. The connections drop at random times and i do not have the time to monitor them all and initiate a trace route once i discover one down.

I would like to write a ping script that will ping a selection of devices every 10 seconds or so and if the ping fails to initiate a trace route to the device.
I also need the outputs to be logged to a txt file.

Thanks,
0
Comment
Question by:-P-Henderson
[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
  • 4
  • 4
8 Comments
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 34914208
Looks like someone allready made that:
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_22882736.html

I hope it helps you as well.
0
 

Author Comment

by:-P-Henderson
ID: 34932507
I'm new to this kind of thing and to be honest the whole script doesn't make much sense,
0
 

Author Comment

by:-P-Henderson
ID: 34932517
-do i need to create a pinglog.txt if so, where does it need to be.
-where does the script source its IP's to ping, i have a range of 15 to ping if possible.
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 35

Expert Comment

by:Ernie Beek
ID: 34933517
ok.

At the moment I have some leakage problems at home so I'm a bit busy right now :-~

I'll have a look as soon as I am able to.
0
 

Author Comment

by:-P-Henderson
ID: 34935758
Leakage,,,, not good.
I've go the ping script working with one Destination IP, just need to know how to get it to work with multiple ip's.
0
 
LVL 35

Accepted Solution

by:
Ernie Beek earned 2000 total points
ID: 34938837
Right, I have dry feet again :)

So back to business. I made some changes to the original script:

 
@ECHO OFF

:VARIABLES

:: **************************************************************
:: * SET VARIABLES                                              *
:: **************************************************************

:: Retrieves a useable date from the system date.
SET yymmdd=%DATE:~8,2%-%DATE:~3,2%-%DATE:~0,2%

:: Change the below variable to desired target name or IP Address.
SET Machine=%1

:: Sets the logfile names and adds date stamp.
SET pinglog=pinglog_%yymmdd%
SET tracelog=tracelog_%yymmdd%

:: Sets the pingcount variable to zero.
SET pingcount=0

:PING

:: **************************************************************
:: * PING ROUTINE: Continuous loop to ping the machine name     *
:: * and write the results of the ping to the pinglog file.     *
:: * If ping fails to communicate with the server the loop will *
:: * exit and move on to the TRACE ROUTINE.                     *
:: **************************************************************

IF EXIST %TEMP%\temp.txt DEL %TEMP%\temp.txt

:: Displays status information on screen.
ECHO.
  ECHO Please wait, pinging %Machine%
ECHO.

:: Performs ping command on the target machine and outputs the
:: results to the pinglog file. If ping fails then will skip
:: to TRACE routine.

ping -w 1000 -n 4 %Machine% >>%TEMP%\temp.txt

for /f "tokens=1,* delims=," %%a in ('type %TEMP%\temp.txt ^| findstr /i "Request timed out"') do GOTO TRACE

  type %TEMP%\temp.txt
  
:: Writes completion message to the pinglog file.
ECHO. >>%pinglog%.txt
  ECHO ========================================================= >>%pinglog%.txt
  ECHO Ping Completed Succesfully at %TIME%                      >>%pinglog%.txt
  ECHO ========================================================= >>%pinglog%.txt
ECHO. >>%pinglog%.txt

:: Displays completion message on the screen.
ECHO.
  ECHO =========================================================
  ECHO Ping Completed Succesfully at %TIME%
  ECHO =========================================================
ECHO.
  
GOTO EOF

:TRACE

:: **************************************************************
:: * TRACE ROUTINE: Will perform a trace route command on the   *
:: * target machine and write the results to the tracelog file. *
:: * Once the trace has completed the routine will exit and go  *
:: * back to executing the PING ROUTINE.                        *
:: **************************************************************

IF EXIST %TEMP%\temp2.txt DEL %TEMP%\temp2.txt

type %TEMP%\temp.txt >>%pinglog%.txt

:: Writes ping failure message to the pinglog file.
ECHO. >>%pinglog%.txt
  ECHO ********************************************************* >>%pinglog%.txt
  ECHO Ping failed at %TIME% executing Trace Route.              >>%pinglog%.txt
  ECHO ********************************************************* >>%pinglog%.txt
ECHO. >>%pinglog%.txt

:: Writes ping failure message to the tracelog file.
ECHO. >>%tracelog%.txt
  ECHO ========================================================= >>%tracelog%.txt
  ECHO %Machine% did not respond at %TIME%                       >>%tracelog%.txt
  ECHO ========================================================= >>%tracelog%.txt

:: Displays ping failure message on the screen.
ECHO.
  ECHO =========================================================
  ECHO %Machine% did not respond at %TIME% 
  ECHO =========================================================
ECHO.

  ECHO Please wait, trace route is processing...

ECHO.
  
:: Performs Trace Route command on the target machine and writes
:: results to the tracelog file.
::   TRACERT %machine% >>%tracelog%.txt
     TRACERT %Machine% >>%TEMP%\temp2.txt
     
     type %TEMP%\temp2.txt >>%tracelog%.txt
     
:: Writes trace route completion message to the tracelog file.
ECHO. >>%tracelog%.txt
  ECHO Trace Route Completed at %TIME% on %DATE%. >>%tracelog%.txt
ECHO. >>%tracelog%.txt  

ECHO.
  ECHO Trace Route Completed at %TIME%
ECHO.

GOTO EOF

:EOF

EXIT /B

Open in new window


And called this one pping.bat

Then I created another little script:

 
@ECHO OFF
:DOPING
for /f %%z in (myhosts.txt) do call pping.bat %%z
GOTO DOPING

Open in new window


And called that runpping.bat

Third I made a txt file:
 myhosts.txt
In which you can put the ip adresses to be pinged.

Put this all together in a directory and run runpping.bat This will continue to run until CTRL-C is pressed.

Have a look to see if this is workable for you.
0
 

Author Closing Comment

by:-P-Henderson
ID: 35060020
My appologies for the delay, this worked a treat.... Thanks
0
 
LVL 35

Expert Comment

by:Ernie Beek
ID: 35060040
Never mind, glad it's working.

And thx for the points :)
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
David Varnum recently wrote up his impressions of PRTG, based on a presentation by my colleague Christian at Tech Field Day at VMworld in Barcelona. Thanks David, for your detailed and honest evaluation!
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
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

649 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