I am writing a little script which picks the best machine out of a few dozen to connect to. It gets a users name and password, and then picks the best machine and gets a hostname. Right now all the script does is print the hostname. What I want is for the script to find a good machine, and open an ssh connection to it with the users provided credentials.
So my question is how do I get the script to open the connection when it exits, so that when the user runs the script, it ends with an open ssh connection.
I am using sshpass.
subprocess.call, without setting up pipes for stdin/out/err and run the ssh connection within python?