pexpect学习阶段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pexpect学习阶段相关的知识,希望对你有一定的参考价值。
网上关于pexpect的介绍基本都类似于这样http://blog.csdn.net/sdustliyang/article/details/23373485,但是并没有关于下述问题的解释
问题:可以ssh到主机,但是后面执行的命令无法生效
代码如下:
1 import pexpect 2 import sys 3 4 child = pexpect.spawn(‘ssh [email protected]‘) 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(‘#‘)
日志信息:
[email protected]‘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命令并没有执行。什么原因呐?我也不知道....网上也找不到
以上是关于pexpect学习阶段的主要内容,如果未能解决你的问题,请参考以下文章