#! The/usr/bin/python
# - * - coding: utf-8 - * -
# coding utf8=
"' shell command" '
The import paramiko
The from paramiko. Py3compat import u
The import time
The class SSHClient (object) :
Def close (self, SSH) :
SSH. The close ()
Def sshclient_execmd (self, the hostname, port, username, password, execmd1) :
Paramiko. Util. Log_to_file (" paramiko. Log ")
Print "s s hostname, port, username, % s," % s "execmd % s % (hostname, port, username, password, execmd1)
# a sshclient object
SSH=paramiko. SSHClient ()
# allows the trusted host will be automatically added to the host_allow list, this method must be put in front of the connect method
SSH. Set_missing_host_key_policy (paramiko. AutoAddPolicy ())
SSH. Load_system_host_keys ()
# call the connect method to connect server
SSH. Connect (hostname=the hostname, port=port, username=username and password=password)
Try:
# execute the command
Stdin, stdout, stderr=SSH. Exec_command (execmd1)
# results to stdout, if there are any errors will be put in stderr
# stdin. Write (" Y ") Generally speaking, the first connection, need a simple interaction.
# print (stdout. Read (). The decode ())
Print stdout. Read ()
SSH. The close ()
Except:
# closes the connection
SSH. The close ()
Print (" BUG ")
#
# if __name__=="__main__ ':
# pass
CodePudding user response:
Y9MXSIF79G-eyJsaWNlbnNlSWQiOiJZOU1YU0lGNzlHIiwibGljZW5zZWVOYW1lIjoiSkJGYW1pbHkgQ2hpbmEiLCJhc3NpZ25lZU5hbWUiOiIiLCJhc3NpZ25lZUVtYWlsIjoiIiwibGljZW5zZVJlc3RyaWN0aW9uIjoiIiwiY2hlY2tDb25jdXJyZW50VXNlIjpmYWxzZSwicHJvZHVjdHMiOlt7ImNvZGUiOiJJSSIsImZhbGxiYWNrRGF0ZSI6IjIwMTktMDctMjYiLCJwYWlkVXBUbyI6IjIwMjAtMDctMjUifSx7ImNvZGUiOiJBQyIsImZhbGxiYWNrRGF0ZSI6IjIwMTktMDctMjYiLCJwYWlkVXBUbyI6IjIwMjAtMDctMjUifSx7ImNvZGUiOiJEUE4iLCJmYWxsYmFja0RhdGUiOiIyMDE5LTA3LTI2IiwicGFpZFVwVG8iOiIyMDIwLTA3LTI1In0seyJjb2RlIjo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