Python Forum

Full Version: connect via ssh to a remote host and run a command locally
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

i'm new to python, please don't hold that against :-)

i'm looking to ssh into a remote computer and run a command locally, this is what i have so far but the local command doesn't seem to run.

if i run it without this command, i receive "Done."
stdin, stdout, stderr = client.exec_command("svt-shutdown-safe")

but when i run it with the above line, it get an error and the "svt-shutdown-safe" command doesn't run.

any help is much appreciated.

import paramiko

try:
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 

    client.connect("10.0.0.0", port="22", username="MyUsername", password="MyPassword")

    stdin, stdout, stderr = client.exec_command("svt-shutdown-safe")
    
finally:
    client.close()

print ("done.")