Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

SSH using expect

Posted by crystal (crystal), 3 August 2006
Please tell me how to login to a remote machine using SSH...I dont understand what material i find regarding this ...

right now i am using a code:

#!/home/pub/bin/expect -c
#The above line provides the path of the expect tool in unix.

set UserID "administrator"
set Passphrase "Administrator1@"
set remotehost "172.16.61.174"
spawn ssh -l $UserID $remotehost
expect -re "Enter passphrase for key '.*':"
send "yes\r"
send "$Passphrase\r"

expect "C:\>"
send "hostname\r"



I dont understand how its 'trying' to connect and after running this is whats displayed  


spawn ssh -l administrator 172.16.61.174
administrator@172.16.61.174's password:
Permission denied, please try again.
administrator@172.16.61.174's password:


Please tell me how to connect to a remote machine and what exactly is going on in each script  

Posted by admin (Graham Ellis), 3 August 2006
I suggest you go through the SSH login with all the options manually, making notes of all the various possibilities, then code with spawns, sends and expects to match.   I sometimes describe this process as being rather like writing down the moves for a ballet dance for two dancers.  

You need to note all the options and code for them, and run the code again and again with log_user set to 1 so that you can see anywhere it sticks.

A further word of advise - do NOT end your expect patterns with a wildcarded catch all, as this leads to erratic behaviour; it'll just catch the character stream that's been returned by the ssh up to that point and the timing will differ depending on cpu load and a whole host of other factors.

Posted by crystal (crystal), 3 August 2006
A further word of advise - do NOT end your expect patterns with a wildcarded catch all, as this leads to erratic behaviour; it'll just catch the character stream that's been returned by the ssh up to that point and the timing will differ depending on cpu load and a whole host of other factors.


I have been working with tcl-expect since the past 20 days !!!!

I have no clue what you telling me  

Posted by crystal (crystal), 3 August 2006
#!/home/pub/bin/expect -c


I tried using this code

spawn ssh -l administrator 172.16.61.174
expect "administrator's password: $"
send "Administrator1@\r"

expect "C:\>"
interact
send "hostname\r"


I get this while running it

spawn ssh -l administrator 172.16.61.174
administrator@172.16.61.174's password:

c:\winnt\profiles\Administrator>



Please let me know where can I find resources online to read on SSH login and what you asked me to go through...

Thanks for helping  


Posted by admin (Graham Ellis), 3 August 2006
These elements of expect are things that are best taught / demonstrated in real life / explained.   I would suggest that you book a day's one on one training with us, bring your application along here and we'll look at it if you're having problems with the advise on the board.   As you say, you've been struggling 20 days already; one extra day here will get you past the block you've hit.

Availability - see http://www.wellho.net/share/diary.html
Commercial / venue details - see http://www.wellho.net/course/axfull.html

Posted by crystal (crystal), 3 August 2006
That would have been great only thing is I am in India  



Posted by admin (Graham Ellis), 3 August 2006
.... then perhaps there's someone who offers a similar local service to we do over there.   We certainly get a great deal of Tcl and Expect traffic from India on this board, so I know there's quite heavy usage there ....



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho