在远程机器上递归执行本地定义的python脚本 [英] Recursively execute a locally defined python script on remote machines

查看:31
本文介绍了在远程机器上递归执行本地定义的python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣编写脚本,以便脚本的唯一副本驻留在我的本地机器上,但脚本在远程机器上执行,可能与远程机器在其他远程机器上执行脚本(即 2 或分布式调用树中有更多层次的递归).

I'm interested in writing a script so that the only copy of the script resides on my local machine, but the script executes on remote machines, possibly with the remote machines executing the script on other remote machines (i.e., 2 or more levels of recursion in the distributed invocation tree).

实现这一点的一种方法是一步将脚本复制到远程机器,然后在第二步通过 ssh 执行远程执行,将适当的参数传递给脚本,脚本将为每次远程调用传递不同的参数,每个都将通过以下方式执行:

One way to achieve this would be to copy the script to the remote machines in one step and then perform remote execution via ssh in a second step, passing appropriate parameters to the script, which will pass different parameters for each remote invocation, each of which would be performed via something like:

subprocess.call(['ssh', <user@address>, 'python scriptname.py <params>'])

是否可以在不先复制python脚本的情况下一步实现这一点.显然,我仍然需要以某种方式将脚本中的代码作为远程调用的一部分进行传输,但最好不必运行两个单独的命令,甚至可能不需要运行第三个命令来从远程清理文件脚本运行后的机器.

Is it possible to achieve this in one step without first copying the python script. Obviously, I'd still have to transmit the code in the script as part of the remote call in some way, but it would be preferable not to have to run two separate commands and perhaps even a third to clean up the file from the remote machine after the script is run.

推荐答案

不,你不能一步完成(除了 python -c 'print "hello world"'也许).但是 fabric 可能会让您的生活更轻松一些.

No, you won't be able accomplish this in one step (except for python -c 'print "hello world"' maybe). But fabric might make your life a little easier.

这篇关于在远程机器上递归执行本地定义的python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆