過去幾天我一直和Paramiko一起工作,到目前爲止我很喜歡它,現在我遇到了一個問題,試圖將SSH陷入陷阱。我相信就是這樣,因爲我可以在另一臺服務器上運行相同的腳本,並且效果很好。基本上這個腳本會讓我ssh進入服務器並運行一個命令,但是當它到達stdout或stderr行時會掛起。然後我必須關閉終端窗口並重新打開,因爲它不會讓我CTRL + C脫身。有沒有其他人遇到這個問題,你是如何解決這個問題的。提前致謝!用SSH登錄的Paramiko問題
的paramiko腳本
import paramiko
import getpass
pw = getpass.getpass()
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('example.com', username='usernam', password=pw)
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
print "has connection."
transport = client.get_transport()
transport.set_keepalive(1)
stdin, stdout, stderr = client.exec_command("foo")
data = stdout.read()
f = open('/Users/myMac/directory/foo.txt', 'w')
f.write(data)
f.close()
client.close()
我的日誌
has connection.
DEBUG:paramiko.transport:[chan 1] Max packet in: 34816 bytes
DEBUG:paramiko.transport:[chan 1] Max packet out: 4096 bytes
INFO:paramiko.transport:Secsh channel 1 opened.
DEBUG:paramiko.transport:[chan 1] Sesch channel 1 request ok
DEBUG:paramiko.transport:Sending global request "[email protected]"
DEBUG:paramiko.transport:Sending global request "[email protected]"
DEBUG:paramiko.transport:Sending global request "[email protected]"
DEBUG:paramiko.transport:Sending global request "[email protected]"
DEBUG:paramiko.transport:Sending global request "[email protected]"
DEBUG:paramiko.transport:Sending global request "[email protected]"
DEBUG:paramiko.transport:Sending global request "[email protected]"
....
,並保持下去,直到我關閉終端。
感謝@vanda的:) – tjoenz
我看不出這個問題是如何與SNMP(或特別是SNMP陷阱)相關的。 SNMP陷阱是一種網絡消息,被管理的設備可以發送給管理系統來通知發生的事件。 – Jolta