RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
python远程执行命令
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()

网站题目:python远程执行命令
网站网址:http://sczitong.cn/article/igscdc.html