4

我在远程机器上有一个 python 脚本,我想从我的本地机器上执行它。它需要一些参数,如果我要在那台机器上运行它,这就是我将如何运行它。

python python_parallel.py --num=10 --ssh=/home/user1/path/file.txt

目前,我的本地机器中有一个运行上述脚本的 python 代码:

from optparse import OptionParser
parser.add_option("-n", "--num", type="int", dest="num_spice",help="Enter the number")
parser.add_option("-s", "--ssh", dest="ssh_txt",help="Enter the path to the text file")
num_spice=options.num_spice
ssh_txt=options.ssh_txt

(options, args) = parser.parse_args()

os.system('ssh user1@10.100.10.201 python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) )

有没有更好的方法来做到这一点?我在此链接上尝试了解决方案,但它给了我一个错误“ImportError:没有名为 ssh 的模块”

4

2 回答 2

6

我建议你看一下铅锤模块来做这样的事情。

这是运行本地命令的一种非常酷且简单的方法,您可以很容易地使用远程命令(使用上下文管理器)执行相同操作。

于 2013-03-08T15:22:32.003 回答
2

你考虑过使用Fabric吗?它真的很容易使用。

于 2013-03-08T15:49:48.207 回答