Lsof: Bash command not found while connecting to remote server. The same works on the terminal perfectly.
I've tried to work with three of these libraries for ssh in python: pssh, fabric and paramiko.
The main error is that with the pssh and fabric libraries, most of my commands work i.e ls, df, kill etc. But the lsof command doesn't work. It throws this error 'lsof: bash command not found'. Lsof runs perfectly if I use putty to connect to the terminal and run the same commands.
So, I tried paramiko's invoke_shell variant since it uses the shell channel. While paramiko's invoke_shell runs the lsof command properly, it is time consuming.
Fabric code:
c = Connection()
result = c.run('lsof /lt')
print(result.stdout.strip())
Pssh code:
from __future__ import print_function
from pssh.clients import ParallelSSHClient
hosts = ['host']
client = ParallelSSHClient(hosts, user='usename', password='pass')
output = client.run_command('lsof /lt | grep deleted ', sudo=True)
for host, host_output in output.items():
for line in host_output.stdout:
print(line)
Since I'm very new to this, any help would be really appreciated. Please let me know what's the best way to go about this.