import pexpect, os, sys
cmd = "sudo su -"
p = pexpect.spawn(cmd, timeout=60)
pass_expect = ".*assword.*" (as I get a prompt saying "[sudo] password for user" )
p.expect(pass_expect)
print "I want the password"
p.sendline("mypassword")
p.logfile = sys.stdout
p.sendline("logout")
p.close()
I am getting the following error while executing the above script
Error
Traceback (most recent call last):
File "test.py", line 11, in p.expect(pass_expect)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
version: 2.3 ($Revision: 399 $)
command: /usr/bin/sudo
args: ['/usr/bin/sudo', 'su', '-']
searcher: searcher_re:
0: re.compile(".*assword.*")
buffer (last 100 chars): root@:~#
before (last 100 chars): root@:~#
after:
match: None match_index: None exitstatus: None flag_eof: False pid: 16933 child_fd: 3 closed: False timeout: 60
delimiter: logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1
Can someone please help me out as I am been stuck in this problem from few days.
Any help will be appreciated. Thanks !!