Skip to content

jererc/sshex-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Basic and lightweight ssh expect.

Run commands on ssh hosts and handle prompts (passwords, confirmations, etc).


Example:

    # We run rsync with sudo from a remote host to another remote host

    from sshex import Ssh

    src_host = 'src_host'
    src_username = 'src_username'
    src_password = 'src_password'
    src_path = '/path/src/'

    ssh = Ssh(src_host, src_username, src_password)

    dst_host = 'dst_host'
    dst_username = 'dst_username'
    dst_password = 'dst_password'
    dst_path = '/path/dst/'

    cmd = 'rsync -av %s %s@%s:%s' % (src_path, dst_username, dst_host, dst_path)

    # expect patterns (sudo password is automatically handled)
    expects = [
        (r'(?i)\(yes/no\)', 'yes'),
        (r'(?i)\bpassword\b', dst_password),
        ]

    output, return_code = ssh.run(cmd, expects=expects, use_sudo=True)

    print 'output:', output
    print 'return code:', return_code

About

Basic and lightweight ssh expect

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages