我试图找到一种取消引用goldenClusterID的方法,以在AWS CLI命令中使用它来终止集群。该程序是为了补偿每天生成的动态作业流编号,因此可以应用通过计划的正常数据管道关闭。我可以整天os.system(“ less goldenClusterID”)给我正确的答案。但是,它不会直接取消引用就放弃了好东西。有什么建议吗?

from __future__ import print_function

import json
import urllib
import boto3
import commands
import os
import re
import datetime
import awscli

foundCluster = ""
rawClusterNum = ""
mainClusterNum = ""
goldenClusterID = ""

#   Next, we populate the list file with clusters currently active
os.system("aws emr list-clusters --active >> foundCluster")
#   We search for a specific Cluster Name
os.system("fgrep 'AnAWSEMRCluster' foundCluster")
os.system("grep -B 1 DrMikesEMRCluster foundCluster >> rawClusterNum")
#   Look for the specific Cluster ID in context with it's Cluster Name
os.system("fgrep 'j-' rawClusterNum >> mainClusterNum")
#   Regex the Cluster ID from the line
os.system("grep -o '\j-[0-9a-zA-Z]*' mainClusterNum >> goldenClusterID")
#   Read the Cluster ID from the file and run AWS Terminate on it
os.system("aws emr describe-cluster --cluster-id %s" % goldenClusterID")
os.system("aws emr terminate-clusters --cluster-ids goldenClusterID")
os.system("rm *")

最佳答案

没关系,我知道了。咖啡过多,睡眠不足。答案是使用:
    goldkeyID = open('goldenClusterID','r')。read()
    os.system(“ aws emr describe-cluster --cluster-id%s”%goldkeyID)

关于python - 寻找一种取消引用包装在python命令调用中的bash var的方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38468720/

10-13 04:55