0

我有一个应用程序,我拼凑在一起尝试生成 3 个线程并同时通过 ssh 进入服务器。我写了一个明显带有冒犯性的编码应用程序,我知道这是错误的,我正在寻找一些指导,以完成我上面提到的最初的最终目标。

对于参数传递,我知道我需要稍后使用 cmd 或 cmd2 之类的东西来处理它,但现在这不是我主要关心的问题。

我知道现在我正在生成一个子进程并连续做事。我期待着您的回复。

#!/usr/bin/python
import sys, os
import subprocess

if (len(sys.argv) > 1):
    if( sys.argv[1] == 'start' ):
        print "starting jboss"
    arg = str(sys.argv[1])
    elif( sys.argv[1] == 'stop' ):
        print "stopping"
    elif( sys.argv[1] == 'status' ):
        print "getting status"
    arg = str(sys.argv[1])
    print arg
    else:
        print "start or stop?"
    exit(1)
else:
    print "unexpected error"


host = "10.24.14.10 "
command = "sudo /etc/init.d/jbossas " + arg 
fullcommand = "ssh " + " " +  host + " " + " " + command  + " "+ arg 


print "full command: ", fullcommand

process = subprocess.Popen(fullcommand, shell=True,
    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output,stderr = process.communicate()
status = process.poll()
print output


host = "10.24.14.20 "
fullcommand = "ssh " + " " +  host + " " + " " + command  + " "+ arg 

process = subprocess.Popen(fullcommand, shell=True,
    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output,stderr = process.communicate()
status = process.poll()
print output


host = "10.30.1.1 "
fullcommand = "ssh " + " " +  host + " " + " " + command  + " "+ arg 

process = subprocess.Popen(fullcommand, shell=True,
    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output,stderr = process.communicate()
status = process.poll()
print output
4

0 回答 0