Script synax that waits on user input before committing changes?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
We want to create a script that will do the following:

show port 5:2,6:1 info
Wait for user to answer if the ports shown are the correct ports to be disabled
If yes execute "disable port 5:2,6:1", then execute "save config"
If no abort

I haven't been able to find a tcl example that incorporates waiting for user input with a if/then.
Photo of Stephen Stormont

Stephen Stormont

  • 822 Points 500 badge 2x thumb

Posted 3 years ago

  • 0
  • 1
Photo of Dorian Perry

Dorian Perry, Employee

  • 2,302 Points 2k badge 2x thumb
Hi Stephen,

I think you may be looking for the Built-In Function: $READ(prompt)

#Example:
set var CLI.OUT " "
show port 5:2, 6:1 information
show var CLI.OUT

set var answer $READ(Are these the correct ports to be disabled?)

#logic based on input
Photo of Matthew Helm

Matthew Helm, Employee

  • 1,852 Points 1k badge 2x thumb
or something like:

disable clip
set var ports "1,2"
set var cli.out 0
show ports $ports info detail
show var cli.out
set var ok $TCL(concat "Disable ports" $ports "?")
show var ok
set var ok $READ(yes or no?)
set var t $TCL(string equal $ok "yes")
if $t then
   disable port $ports
   save
endif
Photo of Stephen Stormont

Stephen Stormont

  • 822 Points 500 badge 2x thumb
Thanks!  Any way we can also echo the saving progress without showing the rest of the code?
Photo of Matthew Helm

Matthew Helm, Employee

  • 1,852 Points 1k badge 2x thumb
Well, not really the saving process... but I added the "show var cli.out" after the "save" line and below is that is the output.

disable clipset var ports "1,2"
set var cli.out 0
show ports $ports info detail
show var cli.out
set var ok $TCL(concat "Disable ports" $ports "?")
show var ok
set var ok $READ(yes or no?)
set var t $TCL(string equal $ok "yes")
if $t then
   disable port $ports
   save
   show var cli.out
endif


....


Disable ports 1,2 ?             yes or no?
 yes
The configuration file primary.cfg already exists.
Saving configuration on master Node .. done!
Configuration saved to primary.cfg successfully.
Photo of Stephen Stormont

Stephen Stormont

  • 822 Points 500 badge 2x thumb
Perfect!  Thanks a lot!