30 lines
867 B
Python
30 lines
867 B
Python
import paramiko
|
|
import sys
|
|
|
|
def run_ssh_command(host, user, password, command):
|
|
client = paramiko.SSHClient()
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
try:
|
|
client.connect(hostname=host, username=user, password=password, timeout=10)
|
|
stdin, stdout, stderr = client.exec_command(command)
|
|
|
|
exit_status = stdout.channel.recv_exit_status()
|
|
out = stdout.read().decode()
|
|
err = stderr.read().decode()
|
|
|
|
if out:
|
|
print(out)
|
|
if err:
|
|
print(err, file=sys.stderr)
|
|
|
|
sys.exit(exit_status)
|
|
except Exception as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
finally:
|
|
client.close()
|
|
|
|
if __name__ == "__main__":
|
|
cmd = sys.argv[1]
|
|
run_ssh_command("161.97.93.156", "carlos", "Innova1978+*?", cmd)
|