Search code examples
tcltelnet

Sending a parameter to Telnet using TCL


I am trying to create a script using TCL to configure a router via telnet. but I am not able to pass a Parameter to telent . What I need the command to look like is : "Bandwidth 10 10" a = 10 . when sending

Bandwidth 10 10 - all is working but when sending Bandwidth $a $a - says invalid command.

what I tried is :

'Bandwidth $a $a' - in this case I do see 10 10 , but it doesn't recognize bandwidth as a command.

other cases like : {Bandwidth '$a $a') || {Bandwidth '$a' '$a'} || {Bandwidth $a $a} || {Bandwidth [ expr ($a) expr ($a)] doesnt work for me.

this is the code :

activate_commands_via_telnet $RouterWanIP [list {bandwidth '$a $a'} {exit}] 

Solution

  • Did you try doing this?

    activate_commands_via_telnet $RouterWanIP [list "bandwidth $a $a" {exit}] 
    

    The double quotes allow Tcl to substitute the value of the a variable inside there.