pexpect学习阶段

  网上关于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@ip's 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命令并没有执行。什么原因呐?我也不知道....网上也找不到

转载于:https://www.cnblogs.com/woniujun/p/7407112.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值