tbeauvais
tbeauvais

Reputation: 1738

Python script to create SSH connection

I'm trying to write a script that will take a single string (machine name) and use Amazon API to find that machine and get the DNS and SSH into the machine. If it were a bash script I could simply put in an ssh command and it would create the connection and the user wouldn't notice anything. How do I do that in Python though? I essentially want the script to end and the terminal to SSH into the machine.

Upvotes: 3

Views: 3127

Answers (1)

For querying EC2 resources, use the boto library.

For running the ssh, use the subprocess.call (no need to end the script though).

import subprocess
addr = '10.20.30.40'
subprocess.call([ 'ssh', addr ])

Upvotes: 2

Related Questions