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

3
  • 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? Commented Apr 9, 2020 at 5: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. Commented Apr 9, 2020 at 13:32
  • Didn't realise that was a thing, thanks for letting me know. Commented Apr 9, 2020 at 20:11

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.