Python 官方文档:入门教程 => 点击学习
import paramiko def sshclient_execmd(hostname, port, username, passWord, execmd): paramiko.util.log_to_file("paramik
import paramiko
def 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()
--结束END--
本文标题: python远程执行命令
本文链接: https://www.lsjlt.com/news/184046.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0