我正在尝试找到一种取消引用 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 *")
最佳答案
没关系,我已经明白了。咖啡喝太多, sleep 不足。答案是使用: goldkeyID=open('goldenClusterID', 'r').read() os.system(“aws emr 描述集群 --cluster-id %s” % goldkeyID)
关于python - 寻找一种方法来取消引用包含在 python 命令调用中的 bash var,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38468720/