Before you down vote this, let me say that I've read ALOT of questions on this subject on SO and haven't found the answer. This one has the closest thing to what I need though on the answer by "Neil".
What is the simplest way to SSH using Python?
I would like to find a way to log into another host using ssh, providing a password, without importing non-standard python modules. I would then need to be able to send multiple commands using the ssh connection. I need to do this because I need to automate something on a lot of closed systems that I cannot get new modules on to (non internet accessible).
The answer in the referenced question is:
If you want to avoid any extra modules, you can use the subprocess module to run
ssh [host] [command] and capture the output.
Try something like:
process = subprocess.Popen("ssh example.com ls", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) output,stderr = process.communicate() status = process.poll() print output To deal with usernames and passwords, you can use subprocess to interact with the ssh process, or you could install a public key on the server to avoid the password prompt.
Which sounds good, but I can't quite understand this well enough to take it farther. Can someone help me to get a baby step going?
(1) log in to ssh
(2) provide the password when its prompted
(3) issue an ls command and display the result
I can do the rest of the automation if I can just get pass password entry.
PS: I tried using expect, but TCL isn't on the system so please don't tell me to use that! If you know something else I can call to aid python I'm happy to try it though as long as its likely to be built into a Fedora Enterprise Linux system by default.