Solved

Ping Script & automatic trace route

Posted on 2011-02-16
8
786 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
  • 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
 
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
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 

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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

As dyndns has reduced the capabilities of the free service, I looked around for other free providers of Dynamic DNS service. After testing several I decided to move my DNS hosting to Hurricane Electric as then domains that require dynamic hostnam…
Quality of Service (QoS) options are nearly endless when it comes to networks today. This article is merely one example of how it can be handled in a hub-n-spoke design using a 3-tier configuration.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now