码迷,mamicode.com
首页 > 其他好文 > 详细

pexpect学习阶段

时间:2017-08-22 00:15:35      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:sim   pre   日志信息   letters   ...   board   void   sftp   logfile   

  网上关于pexpect的介绍基本都类似于这样http://blog.csdn.net/sdustliyang/article/details/23373485,但是并没有关于下述问题的解释

  问题:可以ssh到主机,但是后面执行的命令无法生效

  代码如下:

 1 import pexpect 
 2 import sys
 3 
 4 child = pexpect.spawn(ssh user@ip)
 5 fout = file(mylog.txt,w)
 6 child.logfile = fout
 7 
 8 child.expect(password:)
 9 child.sendline(mypassword)
10 
11 child.expect(#)
12 child.sendline(ls /home)
14 child.expect(#‘)

日志信息:
user@ips password: mypassword

  ######################################################################
  #                              Notice                                #
  #                                                                    #
  #  1. Please DO NOT upgrade the kernel, as the kernel upgrade would  #
  #   damage the original operating system.                            #
  #                                                                    #
  #  2. Please create unique passwords that use a combination of words,#
  #   numbers, symbols, and both upper-case and lower-case letters.    #
  #   Avoid using simple adjacent keyboard combinations such as        # 
  #   "Qwert!234","Qaz2wsx",etc.                                       #
  #                                                                    #
  #  3. Unless necessary, please DO NOT open or use high-risk ports,   #
  #   such as Telnet-23, FTP-20/21, NTP-123(UDP), RDP-3389,            #
  #   SSH/SFTP-22, Mysql-3306, SQL-1433,etc.                           #
  #                                                                    #
  #                     Any questions please contact 4000-955-988      #
  ######################################################################
ls /home

可以看到ssh是成功连接的,但是ls /home命令并没有执行。什么原因呐?我也不知道....网上也找不到

pexpect学习阶段

标签:sim   pre   日志信息   letters   ...   board   void   sftp   logfile   

原文地址:http://www.cnblogs.com/woniujun/p/7407112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!