To initiate a Python script on a distant computer using SSH from within Python, you can use the paramiko library which allows to execute commands remotely through an SSH connection.
Here is an example code snippet:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# replace hostname, username and password with correct values
ssh.connect('hostname', username='username', password='password')
# replace script_path with the path to the python script on the remote computer
stdin, stdout, stderr = ssh.exec_command('python script_path')
# print the output of the script
print(stdout.readlines())
ssh.close()
This code will create an SSH connection to the remote computer, execute the specified Python script and print its output. Make sure to replace the placeholders with the correct values (hostname, username, password, script_path).
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-05-19 11:00:00 +0000
Seen: 6 times
Last updated: Jun 01 '21
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?