Categories
python

Using Python to Automate SSH Connection and Run Commands

We will be using a  http://fitztrev.github.io/shuttle/ and the pexpect python library. Here is what the shuttle menu looks like. Mine could be named better. #!/usr/bin/python from pexpect import * import pexpect PROMPT = [‘# ‘, ‘>>> ‘, ‘> ‘,’\$ ‘] def send_command(child, cmd): child.sendline(cmd) child.expect(PROMPT) print child.before child.interact() def connect(user, host, password): ssh_newkey = ‘Are you […]