2

I am successfully executing commands over SSH using the following code:

import paramiko

hosts = ["192.168.1.156"]

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

for host in hosts:
    client.connect(host, username='user', password='******')
    stdin, stdout, stderr = client.exec_command("df -H")
    output = ''.join(stdout.readlines())

Print(output)

However as soon as I swap the "df -H" command for "smartctl -H disk1", I get no output from Python. It's probably worth mentioning that I do not get any errors either.

When I run "smartctl -H disk1" in terminal it works fine and gives the output I would expect, but it's just running it through the Paramiko command that seems to be the issue.

Any ideas?

Cheers,

George

George
  • 25
  • 5
  • 1
    *"I do not get any errors either"* – Do you mean that you get no output on `stderr`? Or that you do not get any Python errors? + Have you seen [Command executed with Paramiko does not produce any output](https://stackoverflow.com/q/56066517/850848)? – Martin Prikryl Apr 09 '20 at 05:59
  • Thanks for the reply, output was working fine with a different command such as "df -H" or "mount" but as soon as 'smartctl' was used there was no output. Thanks for the link, it wasn't actually the answer but the link within that answer solved my problem. – George Apr 09 '20 at 13:32
  • Didn't realise that was a thing, thanks for letting me know. – George Apr 09 '20 at 20:11

1 Answers1

0

Depending on which command wasn't working.

client.exec_command("smartctl -H disk1")

I then entered "which smartctl" into a terminal which gave "/usr/local/bin/smartctl"

Substituting this instead of just smartctl, works a treat.

Eg client.exec_command("/usr/local/bin/smartctl -H disk1")

Cheers!

George
  • 25
  • 5