我試圖使用Paramiko遠程運行tcpdump。無法使用Paramiko遠程執行tcpdump
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip_machine, username='root', password=password)
my_command = 'sudo timeout 10 tcpdump -i eth0 ip -w somefile'
stdin, stdout, stderr = ssh.exec_command(my_command)
channel = stdout.channel
channel.recv_exit_status()
ssh.close()
程序立即退出,儘管timeout
命令和recv_exit_status
。 tcpdump的輸出文件被創建,但它是空的。
做什麼'打印stdout.read()'和'打印stderr.read()'顯示替換它? –
sudo:對不起,你必須有一個tty來運行sudo – Bob