Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Attention: The Community will be in read-only mode on 12/14/2017 from 12:00 am pacific to 11:30 am.

During this time you will only be able to see content. Other interactions such as posting, replying to questions, or marking content as helpful will be disabled for few hours.

We apologize for the inconvenience while we perform important updates to the Community.

New Member

regex problem TCL scripts

Hello,

So my first problem is I'm trying to create a tcl script which will print out the file name of the image currently running. I've got this so far.

set output [ split [ exec "show version" ] "\n" ]

foreach line $output {

        if { [ llength $line ] > 0 } {

                if { [ regexp "^.+?System image file is \"(.+?)\"" [ lindex $line 0 ] ] } {

                        puts $line

                }

        }

}

Now what bugs me to hell is this:

If I save the show version in a file and run egrep with the regex "^.+?System image file is \"(.+?)\"" I get the reply:

System image file is "flash:c181x-advipservicesk9-mz.124-15.T3.bin"

However when I run the tcl script in the router I don't get any hit.... and this is very confusing. The only time I've actually gotten a hit was when I just wrote the regex ^System, but then I get 3 lines and in the end all I actually want to return is the image file name and nothing else. I had planned to use something like "c18(.+?)[bin]" to do that but the TCL script complained as hell on that regex. I know using the c18 is technically a little cheating but it doesn't matter since the script I'm working on will always be running on one type of router (1800 series).

Anyone got a clue to what is going on here? Is cisco regex engine limited? And if this should be on another forum I'm not sure, but I think this was the best place.

Everyone's tags (4)
774
Views
0
Helpful
0
Replies
CreatePlease to create content