Hi,

I have written a small code to connect to solaris machine from cygwin...but this code is giving some error. please see the code below..i am expect some solution of this error.. Thanks in advance

import os, pexpect, time

FirstTime_Ssh='Are you sure you want to continue connecting (yes/no)?'

def ConnectUnix():
connect=pexpect.spawn('ssh sanju@hostname')
#time.sleep(20)
i=connect.expect([FirstTime_Ssh,'.*password:',pexpect.EOF],timeout=100)
print i
if i==0:
print "yes"
connect.sendline('yes')
i=connect.expect([FirstTime_Ssh,'.*password:',pexpect.EOF],timeout=100)
elif i==1:
print "give the password"
time.sleep(20)
connect.sendline('sanju')
time.sleep(20)
print connect.expect(pexpect.EOF,timeout=120)
elif i==2:
print "got the key or connection timeout"
pass
print connect.before


ConnectUnix()


This is the error section:

1
give the password
Traceback (most recent call last):
File "connect.py", line 29, in <module>
ConnectUnix()
File "connect.py", line 22, in ConnectUnix
print connect.expect(pexpect.EOF,timeout=120)
File "pexpect.py", line 1311, in expect
return self.expect_list(compiled_pattern_list, timeout, sea
File "pexpect.py", line 1325, in expect_list
return self.expect_loop(searcher_re(pattern_list), timeout,
)
File "pexpect.py", line 1409, in expect_loop
raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
<pexpect.spawn object at 0x7ff2a0cc>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/ssh
args:
searcher: searcher_re:
0: EOF
buffer (last 100 chars): Generic January 2005
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
hostname%
before (last 100 chars): Generic January 2005
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
hostname%
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 4604
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

All I can tell is that your expect strings never get found. So you would be better to figure out how to do this on the command line, and then replicate those actions using pexpect (since pexpect basically spoofs you performing the same commands (sendline) and waiting for certain responses (expect))

As you can see from the pexpect failure, the last 100 characters of output from your command were the following:

buffer (last 100 chars): Generic January 2005
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
hostname%

Thanks a lot Jim for your comments.

jim My expect string gets found, because of you see the i, its value is 1 which means expect string is able to found the .*password string..

problem starts when i send the password from the sendline..
after sendline its not sending any response.

I don;t know why it is happening because ideally it should return some thing.. :(

Thanks a lot Jim for your comments.

jim My expect string gets found, because of you see the i, its value is 1 which means expect string is able to found the .*password string..

problem starts when i send the password from the sendline..
after sendline its not sending any response.

I don;t know why it is happening because ideally it should return some thing.. :(

When you send your password do you hit 'Enter' ? Add \n after your password to see if that helps.

This article has been dead for over six months. Start a new discussion instead.