I want to execute a Python script on several (15+) remote machine using SSH. After invoking the script/command I need to disconnect ssh session and keep the processes running in background for as long as they are required to.
I have used Paramiko and PySSH in past so have no problems using them again. Only thing I need to know is how to disconnect a ssh session in python (since normally local script would wait for each remote machine to complete processing before moving on).
Running commands remotely on another host from your local machinelink. Using the Paramiko module in Python, you can create an SSH connection to another host from within your application, with this connection you can send your commands to the host and retrieve the output.
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!
This might work, or something similar:
ssh [email protected] nohup python scriptname.py &
Basically, have a look at the nohup
command.
On Linux machines, you can run the script with 'at'.
echo "python scriptname.py" ¦ at now
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With