I'm new to Python programming and I'm trying to ssh using the pexpect code but it fails when I enter the password. Can someone please look into it. Also, Is there a tutorial for pexpect for automating the networking. Please suggest!
Thanks!
This is the entire program. I'm trying to check if I can ssh into the device successfully or not. Thanks!
Thanks!
#!/usr/bin/env python import pexpect ssh_newkey = 'Are you sure you want to continue connecting' # my ssh command line p=pexpect.spawn('ssh [email protected] uname -a') i=p.expect([ssh_newkey,'Password:',pexpect.EOF]) if i==0: print "I say yes" p.sendline('yes') i=p.expect([ssh_newkey,'password:',pexpect.EOF]) if i==1: print "I give password", p.sendline(password) //// fails here p.expect(pexpect.EOF) elif i==2: print "I either got key or connection timeout" pass print p.before # print out the result
Error:Error:
File "test/ssh3.py", line 15
p.sendline(pasword)
^
SyntaxError: invalid syntax
This is the entire program. I'm trying to check if I can ssh into the device successfully or not. Thanks!