tcl - Connecting to switches using SSH and Expect -


I'm a newbie to expect (though many are opening programs). I'm trying to connect to a switch which is expected to be able to dump the ongoing configuration. But somehow my order to send is not sent on the switch.

Script:

  #! / Usr / bin / expect-f proc connect {passw} {hope {"intent:" {send "$ passw \ r" expectation {"prompt & gt;" {Return}}}}} # time-bound return 1 set user [Lindex $ argv 0] Set Paso [Lindex $ argv 1] Host set [lindex $ argv 2] ​​# Check if all were provided {$ user = = "" || $ Passw == "" || $ Host == ""} {say "Uses: & lt; user & gt; & lt; passw & gt; & lt; host & gt; \ n" exit 1} egg ssh -oStrictHostKeyChecking = no -oCheckHostIP = A user $ $ $ host set rez [connect $ passw] if {$ rez ==}} send {send {enable {r} {send running \ r} exit 0} to send "\ \" to connect to switch Error in: $ host, user: $ user! \ N "exit 1"  

When I run the script (triggered from a shell script) I can login it in the switch and press' See Rompt 'do, but then the script exits, because I don'

Richard

No one can show me how to fix it?

after sending the command using send Required to add the expected statement.

  eggs ssh -oStrictHostKeyChecking = no -oCheckHostIP = a user $ $ $ set set rez [connect $ passw] prompt "#" if {$ rez == 0} {send {enabled} R} expectation $ sign; # Waiting for 'prompt' to send {Running show \ r} Expect $ prompt; # After waiting for the prompt to exit, after using the   

without using command , nothing expected Not the SSP process and it will only send the command in a fast way so that you can not get any output.

Another update:

If you are using a different proc for the login purpose, Code> proc , you are recommended to pass the spawn handle. Otherwise, the script may fail because of this, instead of sending / sending it from the process, it will send / send from the studin. Therefore, you should have used it like this,

  proc connect {passw handle} {Hope that {-i $ handle "ash:" {send "$ passw \ r" expectation { -i $ handle "quick>" {Return return}}}} # return 1 set handle [ssh -oStrictHostKeyChecking = no -oCheckHostIP = no $ user @ $ host] set rez [connect $ passw $ handle] set soon "#" if {$ rez timeout Done == 0} {Send -i $ Handle "Enable \ r") Expect --i $ handle $ send quick -i $ handle- "Running r \ r" is expected to run -i $ handle $ prompt Exhaust 0}  

We are saving the SAS spawn handle in variable 'handle' and its use is send and expected and more Being with Vj -i use is to wait for the process


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -