【问题标题】:Execute script in multiple machines using shell script by calling python script通过调用python脚本使用shell脚本在多台机器上执行脚本
【发布时间】:2018-08-08 04:48:29
【问题描述】:

我已经发布了下面的问题,但问题并不清楚。因此,我再次发布确切的要求和示例。这样这一次就不会有人混淆了。

我有一个通用 VM(我将其称为 CVM)和两个远程 VM(我将其称为 RVM1 和 RVM2)。

从 CVM 我必须在 RVM1 和 RVM2 机器上运行 python 脚本。

我在 CVM 中有 shell 脚本。以下是我正在尝试的:

#!/bin/sh
ssh  user@RVM1 "python -u runscript.py 5"
ssh  user@RVM2 "python -u runscript.py 10"
ssh  user@RVM1 "python -u runcommand.sh"

runscript.py:

import os
import sys
a = 10
b = 10
if sys.argv[1] == 10:
 #go back to shell script and wait to complete to shell script line (ssh  user@RVM1 "python -u runcommand.sh")
c = a + b
print c

这可能吗?如果是,请帮助我如何实现这一目标

如果这是不可能的,我怎么能做到这一点,在 RVM2 中执行期间如果 sys.argv[1] == 10,那么它应该跳转到 RVM1 机器并执行命令。再次返回并恢复 RVM2 中的剩余脚本。

注意:RVM1 和 RVM2 无权访问。只有 CVM 可以访问 RVM1 和 RVM2

【问题讨论】:

    标签: python multithreading python-2.7 shell ssh


    【解决方案1】:

    还不清楚,不过试试:

    if sys.argv[1] == 10:
      sys.exit(0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-19
      • 2014-12-18
      • 1970-01-01
      • 2018-08-15
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多