No output when executing smartctl commands over SSH using Paramiko (Python)

Viewed 202

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

1 Answers

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!

Related