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

TCL output not as expected

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
Cisco Employee

Try changing the set and

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

 

2 REPLIES
Cisco Employee

Try changing the set and

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

 

Community Member

You could also bypass the

You could also bypass the regex and use the following:

Router(tcl)#set host [info hostname]

124
Views
0
Helpful
2
Replies
CreatePlease to create content