Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import paramiko
- def execute_command_on_remote_machine(ip_addr, command):
- try:
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(str(ip_addr), username='root', password='****')
- chan = client.get_transport().open_session()
- #chan.get_pty()
- stdin, stderr, stdout = [], [], []
- stdin, stdout, stderr = client.exec_command(command, get_pty=True)
- err_list = [line for line in stderr.read().splitlines()]
- out_list = [line for line in stdout.read().splitlines()]
- client.close()
- return out_list, err_list
- except Exception, e:
- print str(e)
- sys.exit(1)
- output, error = execute_command_on_remote_machine("*.*.*.*", "dinesh")
- print "Output is - ",output
- print "Error is - ",error
- D:dsp_jetbrainsAWS_Persistence>python chk.py
- Output is - ['bash: dinesh: command not found']
- Error is - []
- D:dsp_jetbrainsAWS_Persistence>python chk.py
- Output is - ['lsof: unknown file struct option: d', 'lsof: unknown file struct
- option: i', 'lsof: unknown file struct option: n', 'lsof: unknown file struct op
- tion: e', 'lsof: unknown file struct option: s', 'lsof: unknown file struct opti
- on: h', 'lsof 4.87', ' latest revision: ftp://lsof.itap.purdue.edu/pub/tools/uni
- x/lsof/', ' latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ', ' l
- atest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man', ' usag
- e: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]', ' [-F [f]
- ] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]', '[+|-r [t]] [-s
- [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [-Z [Z]] [--] [names]', "Use t
- he ``-h'' option to get more help information."]
- Error is - []
- chan.get_pty()
- stdin, stdout, stderr = client.exec_command(command, get_pty=True)
- stdin, stdout, stderr = client.exec_command(command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement