- 论坛徽章:
- 0
|
回复 1# play9091
pexpect 行不行?
网上找的- import pexpect
-
- if __name__ == '__main__':
- user = 'forever'
- ip = '192.168.0.200'
- mypassword = 'forever'
-
- print user
- child = pexpect.spawn('ssh %s@%s' % (user,ip))
- child.expect ('password:')
- child.sendline (mypassword)
-
- child.expect(')
- child.sendline('sudo -s')
- child.expect (':')
- child.sendline (mypassword)
- child.expect('#')
- child.sendline('ls -la')
- child.expect('#')
- print child.before # Print the result of the ls command.
- child.sendline("echo '112' >> /home/forever/1.txt ")
- child.interact() # Give control of the child to the user.
复制代码 |
|