pythonsshparamikoiperf

How to make Paramiko run non-standard commands like iPerf


I want to send a command between two laptops using ssh and using Paramiko to do it. Commands such as ls and echo are working as expected, but when using non-standard commands like iPerf I get the following error:

['bash: iperf: command not found\n']

The command works fine if I open an ssh connection through my manual terminal.

Here is the code:

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=HOST, username=USER, password=PWD)
stdin, stdout,stderr = ssh.exec_command("iperf -s")

Solution

  • This happens when you have a shell profile like ~/.bashrc which sets your PATH environment variable to include nonstandard executable search paths.

    To fix it, simply find out where iperf is located by logging in manually and running which iperf. Once you have that full path, use it in your exec_command().

    For example, your new code might look like this:

    ssh.exec_command("/opt/local/bin/iperf -s")