我试图使用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