Help on tclsh there must be better way?

itdaddyitdaddy Member Posts: 2,089 ■■■■□□□□□□
Okay CCNPers.
I understand the tcl script below but being the scripting monkey that I am. I want to make my script do this. I think it is a waste for me to see lines of lines of icmp pings and results.
I want to see at the end of my script run this:

2 failed connections
10.1.200.1
10.1.1.1

I know there has to be a way to do this. If I had a good book or function tutorial on the language I know I could make my script more efficient. I have crappy eyes and I dont need to be perusing the output of 10 plus pings. I want to make my script fin any bad links and report bad pings. Is the tcl script possible ? Or am I dreaming?

Thanks
-Robert

foreach address {

10.1.200.1
10.1.200.2
10.1.200.3
10.1.1.1
10.1.100.1
10.1.100.2
10.1.2.1
192.168.100.1
192.168.100.5
10.1.3.1

} {
ping $address
}

tclquit

Comments

  • mikej412mikej412 Member Posts: 10,086 ■■■■■■■■■■
    itdaddy wrote: »
    Is the tcl script possible ?
    Sure -- you just need to learn Tcl. But unless you have some output (like maybe a . or ! for a ping to each address) you have no idea what's happening. A long list to check and some down/unreachable neighbors could have you sitting there wondering if your script is working.

    Grammar, spelling, punctuation...
    What did you do with the REAL itdaddy? icon_lol.gif
    :mike: Cisco Certifications -- Collect the Entire Set!
  • miller811miller811 Member Posts: 897
    mikej412 wrote: »
    Grammar, spelling, punctuation...
    What did you do with the REAL itdaddy? icon_lol.gif

    Now that made my day.... but it is still early...
    Thanks for the laugh

    icon_lol.gif
    I don't claim to be an expert, but I sure would like to become one someday.

    Quest for 11K pages read in 2011
    Page Count total to date - 1283
  • EdTheLadEdTheLad Member Posts: 2,111 ■■■■□□□□□□
    mikej412 wrote: »
    Grammar, spelling, punctuation...
    What did you do with the REAL itdaddy? icon_lol.gif

    He's been replaced with Robert.
    Networking, sometimes i love it, mostly i hate it.Its all about the $$$$
  • itdaddyitdaddy Member Posts: 2,089 ■■■■□□□□□□
    OMG you are so funny, dudes! I know I know my grammer and spelling suck sometimes
    because I type way too fast. Sometimes I get crazy and always look at these forums as
    a chat room, you know ITDADDY-Bonics! But IT Daddy will appear here and there and Robert will be on the back burner. But yeah, I know even on my blogs it sucks when reading some of my entries. Spaz I can be sometimes but you dudes make me laugh so hard! hhahaha

    Mike
    I know I need to learn TCL. I was wondering do you know of any good reference. I know
    If I had a good reference book I could make my script better.

    I here what you say about the ping etc..but I am only checking connections and to see
    if I have them right and do not want to look thru a list of 10-20 ip addresses. I have sh% for eyes which really hurts me in Cisco a bit since it is hard for me to read and see so much data at once. I am use to making programs work for me. And if I can make a script display
    only the connections that fail, that is all I need. I see sometimes I may need to see more, but in this case it would be nice to see displayed only what didn't connect. Saves me time.
    Thanks a lot for answering. Do you know of any Good reference for TCL; 3rd party reference
    but if Cisco reference is good great then. I know if a programmer got hold of tcl, he or she might have decent sripts. Thanks
  • mkomonmkomon Member Posts: 37 ■■□□□□□□□□
    Hey,

    I used TCLtutor as a reference when I was learning TCL. You might want to try it too, its homepage is TclTutor : Interactive Computer Aided Instruction for Tcl .

    As for your ping script, maybe this could help:

    fconfigure stdout -buffering none

    proc ping { IP } {
    set PING [ exec "ping $IP repeat 3" ]
    set PING [ regexp -inline -all {[\.!]{3}} $PING ]
    if { [ string first "!" $PING ] == -1 } {
    puts "[format "%-40s %s" "ping $IP" "\[failed\]" ]"
    } else {
    puts "[format "%-40s %s" "ping $IP" "\[ OK \]" ]"
    }
    }

    foreach address {
    192.168.1.1
    192.168.1.2
    192.168.1.3
    192.168.1.4
    192.168.1.5
    } {
    ping $address
    }
  • mikej412mikej412 Member Posts: 10,086 ■■■■■■■■■■
    mkomon wrote: »
    As for your ping script, maybe this could help:
    Sweet! icon_thumright.gif
    Router#show ip int brief
    Interface                  IP-Address      OK? Method Status                Prot
    ocol
    ..................
    Loopback1                  1.1.1.1         YES manual up                    up
    Loopback10                 10.0.0.1        YES manual up                    up
    
    Router#tclsh
    Router(tcl)#proc ping { IP } {
    +>set PING [ exec "ping $IP repeat 3" ]
    +>set PING [ regexp -inline -all {[\.!]{3}} $PING ]
    +>if { [ string first "!" $PING ] == -1 } {
    +>puts "[format "%-40s %s" "ping $IP" "\[failed\]" ]"
    +>} else {
    +>puts "[format "%-40s %s" "ping $IP" "\[ OK \]" ]"
    +>}
    +>}
    
    Router(tcl)#
    Router(tcl)#foreach address {
    +>10.0.0.1
    +>192.168.1.1
    +>192.168.1.2
    +>192.168.1.3
    +>192.168.1.4
    +>192.168.1.5
    +>1.1.1.1
    +>} {
    +>ping $address
    +>}
    ping 10.0.0.1                            [ OK ]
    ping 192.168.1.1                         [failed]
    ping 192.168.1.2                         [failed]
    ping 192.168.1.3                         [failed]
    ping 192.168.1.4                         [failed]
    ping 192.168.1.5                         [failed]
    ping 1.1.1.1                             [ OK ]
    
    Router(tcl)#tclquit
    Router#
    
    Robert -- your homework is to post the script that keeps a count and stores the failed IP Addresses and then does the output like your original post. :D
    :mike: Cisco Certifications -- Collect the Entire Set!
  • itdaddyitdaddy Member Posts: 2,089 ■■■■□□□□□□
    Mkomon

    oh my god is that sweet. and regexp too; man dude you rock
    this is so cool. yeah will look at the tutor site...but yeah
    one of these days might make my own script.

    but way cool dude way cool!
    thanks


    ps. that is why I love scripting. it is for the lazy man! haha
    or in my case the blind man!
    hahah;)
  • itdaddyitdaddy Member Posts: 2,089 ■■■■□□□□□□
    mike you are funny
    my homework. hahha

    I do like this script better; I was only planting the seed. this one is way better
    algorithm. But one day I will make an even better one you will see my friend.
    You wait and see. I have known to push the envelope in scripting...


    hee hee ;)
    scripting rocks; need to study that tutorial!

    thanks guys for your insight you dudes are awesome!

    ps. and you don't even make fun of my crappy typing hahhaa;)
  • mkomonmkomon Member Posts: 37 ■■□□□□□□□□
    I'm glad you guys like it.

    You might want to check out Cisco IOS hints and tricks as well, there is a huge amount of tcl scripts that could inspire you. Everytime I surf there I am always fascinated what cool stuff can be achieved using tcl in routers.
  • itdaddyitdaddy Member Posts: 2,089 ■■■■□□□□□□
    mkomon

    really wow will do. Yeah I love scripts man. amazing whatyou can do with them.
    this one is cool...I really need to add reg expr to my skill base still haven't found a decet tutorial on it. but I know what it is doing ;)

    hey Mkomon, you know of a good reg expr. tutorial. i will be getting that book you recommended thanks
    robert
  • mkomonmkomon Member Posts: 37 ■■□□□□□□□□
    I am still learning all the regexp stuff and I can only say it is practice that makes you a master. I do some python scripting at work and I find regexp's a very convenient way to validate (user) input (from command line/config file/whatever) and to parse it into what I need. So I suggest you start from simple matching rules using basic tutorials and it will all come to you. I found this link useful: Regular Expression HOWTO . It may be python-specific in some parts but the core matching is very similar in tcl as in python, as far as I have seen.
  • itdaddyitdaddy Member Posts: 2,089 ■■■■□□□□□□
    okay cute! thanks a lot I will work on my spelling and punct! it does suck I agree ahhaahhha

    thanks sorry if I was soundling like a jerk, I am not..

    thanks!icon_redface.gif
Sign In or Register to comment.