Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pexpect help needed
#3
#!/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(admin123)     
    p.expect(pexpect.EOF)    
elif i==2:
    print "I either got key or connection timeout"
    pass
print p.before # print out the result
Error:
python test/ssh3.py File "test/ssh3.py", line 15 p.sendline(admin123) ^ SyntaxError: invalid syntax You have mail in /var/spool/mail/root
Reply


Messages In This Thread
Pexpect help needed - by jash - Jan-30-2018, 12:10 AM
RE: Pexpect help needed - by micseydel - Jan-30-2018, 12:24 AM
RE: Pexpect help needed - by jash - Jan-30-2018, 12:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,339 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Use pexpect to send user input alisha17 0 1,946 May-10-2022, 02:44 AM
Last Post: alisha17
  Not able to read the text using pexpect/expect Bipinjohnson 7 4,155 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  Sudden Problem with pexpect gw1500se 3 2,466 Nov-19-2021, 11:21 PM
Last Post: bowlofred
  How to use pexpect in python? tiho_bg 1 1,568 Oct-30-2021, 02:50 PM
Last Post: Yoriz
  Pexpect timesout before executing whole output eagerissac 0 1,540 Jun-23-2021, 03:30 AM
Last Post: eagerissac
  pexpect startup help korenron 2 3,541 Apr-27-2021, 07:23 AM
Last Post: korenron
  Problem with pexpect.exception.TimeOUT korenron 0 3,355 Apr-12-2021, 03:25 PM
Last Post: korenron
  Request help on pexpect rsurathu 4 5,900 Jul-19-2020, 03:35 PM
Last Post: snippsat
  SIGWINCH ignored when trying to start a screen with the pexpect module StatTark 0 1,882 Jul-06-2020, 10:12 AM
Last Post: StatTark

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020