Import paramikodef sshclient_execmd (Hostname, port, username, password, execmd): paramiko.util.log_to_file ("Paramiko.log") s = Paramiko. Sshclient () s.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) s.connect (Hostname=hostname, port=port, username=username, password=password) stdin, stdout, stderr = s.exec_command (Execmd) stdin.write ("Y") print stdout.read () s.close () Def main (): hostname = ' 192.168.56.11 ' port = 22 username = ' Root ' password = ' 123456 ' execmd1 = '/root/tomcat/bin/stop.sh ' execmd2 = "/root/tomcat/bin/Start.sh " sshclient_execmd (hostname, port, username, password, EXECMD1) sshclient_execmd (hostname, port, username, password, EXECMD2) if __name__ == "__main__": main ()
This article is from the "Brick Blog" blog, please be sure to keep this source http://wsxxsl.blog.51cto.com/9085838/1956456
Python Remote execution command