0
votes

I have a switch (CLI based) that takes me to the present STP setting when you hit the alphabets (which iam able to automate with tcl) but when it comes to changing the STP setting say from RSTP to MSTP, manually, I have to hit the up arrow and down arrow keys( only option available).

I need help to give the up arrow and down arrow commands in tcl format to automate it.

I read about rlwrap but thats more of history/ file editing which may not be helpful for me. I have tried the " ^[[A" and "[A" options and hexacodes with no success.

I have tried "\u001b[A" etc but the value STP does not change. The CLI is A XML CLI. This is my script . spawn telnet $DUT1_IP expect "login:" send "$user\r" expect "Password:" send "$password\r" expect "sh-3.2#" #sleep 2 send "xml_cli\r" expect ">> " send "bridge_config_mode = STP"

If i have to change mode STP to MSTP i need to use up arrow key in my keyboard to change it to MSTP /RSTP . how to use in expect to handle the same . Please give your thoughts if we can use shell scripting for the same (or any other).

Thanks and Regards Mo

1

1 Answers

1
votes

Up is mapped by your system keyboard driver to a three-character sequence: ^[[A. The first character, rendered as ^[ here, is an Escape character that is not normally renderable on your screen, and you write a real one in a Tcl script with \u001b. Down is correspondingly ^[[B. (Strictly, it could be other character sequences — it depends on the terminal type after all — but virtually everything uses the same thing here, and thank goodness!)

Let's simplify things for you by putting those key sequences in variables (we also need a backslash before the real [ because it is a Tcl metasyntax character):

set up   "\u001b\[A"
set down "\u001b\[B"

Now you can do this to send the characters to the remote side:

send $up
expect "...whatever..."
send $down
expect "...blah..."