| 123456789101112131415161718192021222324252627282930313233343536 |
- import paramiko
- import sys
- def run_remote_command(hostname, username, password, command):
- try:
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(hostname, username=username, password=password)
-
- stdin, stdout, stderr = client.exec_command(command)
- output = stdout.read().decode()
- error = stderr.read().decode()
-
- client.close()
- return output, error
- except Exception as e:
- return None, str(e)
- if __name__ == "__main__":
- host = "192.168.130.171"
- user = "roni"
- pw = "BTSai123"
- cmd = "ollama --version && echo '---' && curl -s http://localhost:11434/api/version"
-
- print(f"Connecting to {host}...")
- out, err = run_remote_command(host, user, pw, cmd)
-
- if out is not None:
- with open("scratch/remote_output.txt", "w", encoding="utf-8") as f:
- f.write(out)
- print("Output written to scratch/remote_output.txt")
- if err:
- print("--- Error ---")
- print(err)
- else:
- print(f"SSH Error: {err}")
|