06-27-2014 02:08 AM
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
Solved! Go to Solution.
06-27-2014 06:00 AM
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
06-27-2014 06:00 AM
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
07-06-2014 07:16 PM
You could also bypass the regex and use the following:
Router(tcl)#set host [info hostname]
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide