Python模块paramiko可以实现用SSH登录服务器,并执行shell
#!/usr/bin/python
import
sys
import
paramiko
def
pycmd(server, port, username, password, shellcmd):
ssh
=
paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()
ssh.connect(server, port, username, password)
stdin, stdout, stderr
=
ssh.exec_command(shellcmd)
print
stdout.readlines()
ssh.close()
if
_name__
=
=
"__main__"
:
pycmd(
"xxx.xxx.xxx.xxx"
,
22
,
"root"
,
"password"
, sys.argv[
1
])