Automate SSH process

Viewed 24

I am a network engineer who SSHs into multiple routers/switches on daily basis. Every time when I want to login to a host, I have to grab the management IP address of the host from a different device and initiate the SSH from our central management access server.

I am trying to automate it using python. I broke the requirements down to three parts:

  1. Identify the host's management IP address - Complete
  2. Log into central management server via SSH
  3. Inititate SSH connection from that server

I don't want to execute any commands through the script. I want it to be an interactive command line where the initial login process is automated. For example, If a user wants to log into gltt01, the script should be able to grab the management IP address of the device and initiate ssh connection to it.

When I tried to use os.system to pass the ssh command as below, the script is not sending the password.

os.system ("ssh 10.1.1.10")
time.sleep(5)
os.system ("password")

I tried subprocess, but no luck there either. I don't want to over-complicate it, I just want the script to execute the ssh commands and login to the device and let the user handle the rest.

0 Answers
Related