对于AWS python脚本,command.getoutput无法获取“ eb status”的输出值

时间:2018-07-28 13:26:13

标签: python amazon-web-services

我的环境是:AWS Windows2012作为Fortress机器,我在此机器上编写了python脚本,目的是在AWS Beanstalk上自动部署,beanstalk之上的机器是Linux系统。为了使用linux命令,我在Windows 2012上安装了cygwin。

首先,我在Windows 2012 cmd中运行“ eb status”:

C:\Users\Administrator>eb status "tcl-stage"|grep Health|gawk -F ":" "{print $2}"|sed s/[[:space:]]//g

输出为:

C:\Python27\lib\site-packages\dateutil\parser\_parser.py:1175: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
elif res.tzname and res.tzname in time.tzname:

Green

上面的“绿色”是正确的输出值。

图片是这样的: enter image description here

我写的脚本是这样的:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import urllib2
import json
import os
import sys
import time
import boto.ec2
import commands

fr = open('C:/text.txt','r')
txt = fr.read()
dictionfo = json.loads(txt)
fr.close()

def tcl():
    k = "tcl"
    g = "arn:aws:elasticbeanstalk:us-west-1::platform/Tomcat 8 with Java 8 running on 64bit Amazon Linux/2.7.7"
    if k in dictionfo:
        os.environ['k'] = str(k)
        os.environ['g'] = str(g) 
        os.environ['i'] = str(dictionfo[k])
        os.system(' echo [profile eb-cli] > C:\\Users\\Administrator\\.aws\\config ')
        os.system(' echo. >> C:\\Users\\Administrator\\.aws\\config ')
        os.system(' echo aws_access_key_id = 123  >> C:\\Users\\Administrator\\.aws\\config ')
        os.system(' echo. >> C:\\Users\\Administrator\\.aws\\config ')
        os.system(' echo aws_secret_access_key = 456  >> C:\\Users\\Administrator\\.aws\\config ')
        os.system(' eb init %k% --region us-west-1 -p %g% ')
        Deploy = raw_input(k + ' will deploy ' + g + ': ').lower()
        if Deploy.startswith('y'):
            os.system(' eb deploy "%k%-stage" --version %i% ')
            c = commands.getoutput(' eb status "%k%-stage"|grep Health|gawk -F ":" "{print $2}"|sed s/[[:space:]]//g ')
            print type(c)
            print c
            if c == 'Green':
                print "%s deploy success" % k
                print "-------------------------"
            else:
                sys.exit(0)
        else:
            sys.exit(0)

但是当我运行此脚本时,输出是这样的: enter image description here

根据我的想法,C的值应为绿色,但其值为空。我想问什么错?如何解决这个问题?

0 个答案:

没有答案