remotessh.py Script em python para executar comandos remotos via SSH

Share Button

English Title: remotessh.py script in python to execute remote commands in ssh connection.

This script is very efficient to do backups or execute many commands automatically.

Use:
python remotessh.py [host] [username] [passuord] [“shell_command”]
./remotessh.py [host] [username] [passuord] [“shell_command”]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
#!/usr/bin/python
 
import pxssh
import getpass
import sys
 
 
try:
    s = pxssh.pxssh()
    hostname = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]
    command = sys.argv[4]
    s.login (hostname, username, password)
    s.sendline ('uptime')
    s.prompt()
    print s.before
    s.sendline (command)
    s.prompt()
    print s.before
    s.logout()
except pxssh.ExceptionPxssh, e:
    print "pxssh failed on login."
    print str(e)

Girhub link: github remotessh