Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1942451
  • 博文数量: 424
  • 博客积分: 1291
  • 博客等级: 中尉
  • 技术积分: 2682
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-13 01:34
个人简介

linux oracle 网络安全 编程

文章分类

全部博文(424)

文章存档

2016年(22)

2015年(53)

2014年(57)

2013年(242)

2012年(50)

分类: Python/Ruby

2015-06-02 14:45:14

  1. def ssh_cmd(ippasswdcmdnewpwd):
  2.     ret = -1
  3.     ssh = pexpect.spawn('ssh -q -p36000 root@%s "%s"' % (ipcmd))
  4.     try:
  5.         i = ssh.expect(['password: ''continue connecting (yes/no)?']timeout=5)
  6.         if i == 0 :
  7.             ssh.sendline(passwd)
  8.         elif i == 1:
  9.             ssh.sendline('yes\n')
  10.             ssh.expect('password: ')
  11.             ssh.sendline(passwd)
  12.         ssh.expect('New Password:')
  13.         ssh.sendline(newpwd)
  14.         ssh.expect('Reenter New Password:')
  15.         ssh.sendline(newpwd)
  16.         r = ssh.read()
  17.         ret = 0
  18.     except pexpect.EOF:
  19.         print "EOF"
  20.         ssh.close()
  21.         ret = -1
  22.     except pexpect.TIMEOUT:
  23.         print "TIMEOUT"
  24.         ssh.close()
  25.         ret = -2
  26.     return ret
  27. 参考:http://www.ibm.com/developerworks/cn/linux/l-cn-pexpect1/
阅读(884) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~