#

Monday, April 30, 2018

Tcl Script to Ping Multiple Destinations at Once

Tcl scripting can be used to automate what you do in Cisco CLI. It is basically a scripting language which can be used to simplify a work load you have to do in Cisco IOS. Here is the official reference to learn more about Tcl scripting. http://tcl.tk

Here is a simple code which can be used to ping multiple destinations at once, which will be handy in troubleshooting..

tclsh
foreach X {
1.1.1.2
1.1.1.3
1.1.1.4
} { ping $X }

Where X is the variable name. In the middle of the script are IP addresses which represents the variable X, If you are going to use an extended version of ping, ex:- ping [destination] repeat 100, you have to write the 2nd parenthesis like the following.
{ ping $X repeat 100}

Let's see an actual CLI output; Remember, this should be coded in privileged mode..















To exit from the tcl mode, you can use exit, tclquit or just Ctrl+Z..

Following script which is an expansion to the above displays the pinging and non pinging IPs only with a more readable way.. Try to understand the code with your basic programming knowledge.

tclsh
foreach X {
1.1.1.2
1.1.1.5
1.1.1.3
1.1.1.4
} {
if { [regexp "(!!)" [exec "ping $X repeat 3"] ] } { 
puts "$X --OK--"
} else {puts "$X --Failed--" }
}


3 comments:

  1. Its Very valuable post for everyone & really I read and like this article.

    Free Direct Mail Postcards
    Snap Packs


    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. It is basically a scripting language which can be used to simplify a work load you have to do in Cisco IOS. Here is the official reference to learn more about Tcl scripting. Data Center Architecture Account Manager

    ReplyDelete