Search code examples
pythonunixsshautosys

How to call .ksh file as part of Unix command through ssh in Python


I would like to achieve the following things:

Given file contains a job list which I need to execute one by one in a remote server using SSH APIs and store results.

When I try to call the following command directly on remote server using putty it executes successfully but when I try to execute it through python SSH programming it says cant find autosys.ksh.

autosys.ksh autorep -J JOB_NAME

Any ideas? Please help. Thanks in advance.


Solution

  • Fabric is a good bet. From the home page,

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

    A quick example,

    >>> from fabric.api import run, env, cd, settings, hide, show
    >>> env.host_string='xxx.xxx.com'
    >>> env.user='user'
    >>> env.password='password'
    >>> run('ls -lart')