網上關於pexpect的介紹基本都類似於這樣http://blog.csdn.net/sdustliyang/article/details/23373485,但是並沒有關於下述問題的解釋 問題:可以ssh到主機,但是後面執行的命令無法生效 代碼如下: 可以看到ssh是成功連接的,但是ls /hom ...
網上關於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命令並沒有執行。什麼原因吶?我也不知道....網上也找不到