python多线程ssh应用程序

时间:2012-06-28 01:25:06

标签: python multithreading python-multithreading command-line-tool

我有一个应用程序,我已经拼凑在一起尝试同时生成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

0 个答案:

没有答案