TCL Script to read from line and input in another line

  • 1
  • 1
  • Problem
  • Updated 7 months ago
  • Solved
  • (Edited)
what i am trying to automate is simple, but i have little knowledge about TCL.

1-  issue the following command:

show configuration netlogin.

2- match the underlined part from the below output of the previous command:

* Slot-1  # sh conf "netlogin"
#
# Module netLogin configuration.
#
configure netlogin vlan temp
enable netlogin dot1x mac web-based
configure netlogin authentication protocol-order dot1x mac web-based
configure netlogin add mac-list ff:ff:ff:ff:ff:ff 48
enable netlogin ports 1:1-15,1:17-18,1:20-38,1:43-45,2:3-24,2:28,2:30,2:36-38,2:43-45 dot1x
enable netlogin ports 1:16,1:35-40,1:43-45,2:35-38,2:40,2:43-45 mac
configure netlogin dot1x ports 1:1 timers server-timeout 3 reauth-period 0 reauthentication off
configure netlogin dot1x ports 1:2 timers server-timeout 3 reauth-period 0 reauthentication off



3- input the above in the below command 

configure upm event user-authenticate profile printer ports **HERE**

4- save.

please notice that i want to match only dot1x ports, not the mac.

thanks in advance.
Photo of Ahmed Haroun

Ahmed Haroun

  • 888 Points 500 badge 2x thumb

Posted 8 months ago

  • 1
  • 1
Photo of Necheporenko, Nikolay

Necheporenko, Nikolay, Employee

  • 1,400 Points 1k badge 2x thumb
Hello Ahmed,

The following script returns ports list as an variable 
enable cli scripting
disable clipaging
set var cli.out 0
sh conf "netlogin" | i enable 
set var ss $TCL(split ${cli.out} "\n")
set var sline $TCL(lsearch -glob $ss *ports*dot1x*)
set var sline $TCL(lindex $ss $sline)
set var sline $TCL(regexp -all -inline {\S+} $sline)
set var result $TCL(lindex $sline 3)
show var result

Example:
* Slot-1 Stack.38 # set var cli.out 0
* Slot-1 Stack.39 # sh conf "netlogin" | i enable 
 ss $TCL(split ${cli.out} "\n")
set var sline $TCL(lsearch -glob $ss *ports*dot1x*)
set var sline $TCL(lindex $ss $sline)
set var sline $TCL(regexp -all -inline {\S+} $sline)
set var result $TCL(lindex $sline 3)
show var resultenable netlogin dot1x mac web-based
enable netlogin ports 1:10-20,2:30,2:35-44 dot1x 
enable netlogin ports 2:1-10 mac 
* Slot-1 Stack.40 # set var ss $TCL(split ${cli.out} "\n")
* Slot-1 Stack.41 # set var sline $TCL(lsearch -glob $ss *ports*dot1x*)
* Slot-1 Stack.42 # set var sline $TCL(lindex $ss $sline)
* Slot-1 Stack.43 # set var sline $TCL(regexp -all -inline {\S+} $sline)
* Slot-1 Stack.44 # set var result $TCL(lindex $sline 3)
* Slot-1 Stack.45 # show var result
1:10-20,2:30,2:35-44        
* Slot-1 Stack.46 # 
* Slot-1 Stack.46 # 

Best Regards,
Nikolay
Photo of Ahmed Haroun

Ahmed Haroun

  • 888 Points 500 badge 2x thumb
Thanks Nikolay , That is great.