cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1186
Views
0
Helpful
2
Replies

TCL output not as expected

ketimun123
Level 1
Level 1

I want to retrieve the hostname of the running config.

I started easy with putting the hostname in a variable and this works fine

set HOSTNAME "hostname P3"
set HOST [ regexp -inline {[A-Z0-9]*$} $HOSTNAME ]
puts $HOST

Output:

P3(tcl)#puts $HOST
P3

 

Now, when changing the first line , I get a invalid output:

set HOSTNAME [ exec {sh run | i hostname} ]
set HOST [ regexp -inline {[A-Z0-9]*$} $HOSTNAME ]
puts $HOST

Output:

P3(tcl)#puts $HOST
{}

 

Why this {} and how can it be fixed ?

cheers, keti

1 Accepted Solution

Accepted Solutions

Dan Frey
Cisco Employee
Cisco Employee

Try changing the set and regexp lines.  Do not need "{}"  in the set line.

 

C819-4G(tcl)#set HOSTNAME [ exec sh run | i hostname ]  
hostname C819-4G

C819-4G(tcl)#regexp {hostname (.*)} $HOSTNAME match host
1
C819-4G(tcl)#puts $host                                 
C819-4G

 

View solution in original post

2 Replies 2

Dan Frey
Cisco Employee
Cisco Employee

Try changing the set and regexp lines.  Do not need "{}"  in the set line.

 

C819-4G(tcl)#set HOSTNAME [ exec sh run | i hostname ]  
hostname C819-4G

C819-4G(tcl)#regexp {hostname (.*)} $HOSTNAME match host
1
C819-4G(tcl)#puts $host                                 
C819-4G

 

Robert Radford
Level 1
Level 1

You could also bypass the regex and use the following:

Router(tcl)#set host [info hostname]

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: