从服务器下载文件以将服务器跳转到笔记本电脑

时间:2019-04-04 17:06:25

标签: python

我的环境很复杂。我需要在只能通过跳转服务器访问的服务器上运行一些脚本。

Web服务器(需要运行脚本/home/hno3.sh来生成文件/tmp/hno3.txt)

跳转服务器:将文件hno3.txt从Web服务器传输到此处

笔记本电脑:将文件hno3.txt从跳转服务器传输到此处

这是我写的,显然还不够:

import os
import paramiko
mycommand = raw_input("Enter your command ")
excel = []
with open('server.txt') as f:
    for line in f:
        server = line.rstrip()
        username, password = ('ibmadmin', 'password')
        ssh = paramiko.SSHClient()

        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))

        ssh.connect(server, username=username, timeout=60)
        ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(mycommand)
        print "For Server " + server
        output1 = ssh_stdout.read()
        print ">", output1.rstrip()
        excel.append(output1.rstrip())

        ssh.close()

执行时,我给出了scp命令,以便将文件从Web服务器下载到跳转服务器。

我无法弄清楚如何在Web服务器上执行脚本。有没有一种方法可以从笔记本电脑登录到跳转服务器,然后登录到Web服务器以运行脚本?我的脚本将在笔记本电脑上运行。

0 个答案:

没有答案
相关问题