Automate ssh connection and execution of program with Python’s Paramiko

There is a library built on top of Paramiko that’s perhaps better suited for your needs.

I am speaking of python fabric (of which I have no association)

Fabric is a Python (2.5-2.7) library and command-line tool for
streamlining the use of SSH for application deployment or systems
administration tasks.

It provides a basic suite of operations for executing local or remote
shell commands (normally or via sudo) and uploading/downloading files,
as well as auxiliary functionality such as prompting the running user
for input, or aborting execution.

If I have understood your requirement correctly, your code might look something like this.

from fabric.api import run

@task
def run_a_out()
    run('echo "some input for a.out" | ./a.out')

And you would execute the remote program with

    fab --hosts=someserver run_a_out

If you wanted to dynamically controll what get’s passed into a.out, you can add a parameter to run_a_out() and pass it from the command line.

In short Fabric provides a higher level API for paramiko with most of it’s complexity hidden away.

Leave a Comment