2017-04-19 62 views
0

我想通過Paramiko使用ssh連接思科UCSM。我的命令失敗了。當我手動輸入相同的命令時,它工作正常。請任何人都可以指導我如何解決問題。Paramiko爲SSH思科UCSM失敗

代碼:

import time 
import paramiko 
import getpass 
host = "10.10.10.10" 
username = "admin" 
password = getpass.getpass("Please enter Password:") 
c=paramiko.SSHClient() 
c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
c.connect(host,username=username,password=password) 
print "connection to %s established" %host 
time.sleep(1) 
stdin, stdout, stderr = c.exec_command("scope org db") 
output = stdout.read() 
print output 
time.sleep(2) 
stdin, stdout, stderr = c.exec_command('show service-profile') 
output = stdout.read() 
print output 

輸出:

Please enter Password: 
    connection to 10.10.10.10 established 

            ^
    % Incomplete Command at '^' marker 

手動在UCSM輸入的命令:

ucsm1# scope org db 
ucsm1 /org # show service-profile 

Service Profile: 
Service Profile Name Type    Server Assignment Association 
-------------------- ----------------- ------- ---------- ----------- 
db/SP-DB1 
        Instance   8/7  Assigned Associated 

ucsm1 /org # 

感謝,

回答

1

不是exec_command,可以嘗試:

remote_conn = remote_conn_pre.invoke_shell() 
output = remote_conn.recv(65535) 
remote_conn.send('scope org db\n')