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
26
27
28
29
30
31
32
33
34
35
|
import paramiko
hostname = 'was1'
port = 22
username = 'mqm'
password = 'redhat'
cmd =
if __name__ = = '__main__' :
paramiko.util.log_to_file( 'paramiko.log' )
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname,port,username,password)
stdin,stdout,stderr = s.exec_command(cmd)
print stdout.read()
print stderr.read()
s.close()
|
注:远程主机必须能解析python程序所在主机的主机名,否则程序执行非常缓慢。
本文转自1321385590 51CTO博客,原文链接:http://blog.51cto.com/linux10000/1773269,如需转载请自行联系原作者