python - 寻找一种方法来取消引用包含在 python 命令调用中的 bash var

标签 python linux bash amazon-web-services emr

我正在尝试找到一种取消引用 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/

相关文章:

macos - 将 mysql 添加到我的 .bashrc PATH

bash - 在系统调用中以编程方式触发 shell 的自动完成事件并获取输出

linux - Shell 嵌套变量无法识别

python - 在不使用浏览器的情况下使用 Python 捕获嵌入式谷歌地图图像

python - 由于我的脚本中存在 'å' ,因此无法运行脚本

linux - bash Linux : start multiple program in parallel and stop all when one has finished

linux - 如果程序由 linux 命令屏幕启动,如何使程序从文件接收 "standard"输入?

python - 如何避免使网络服务器成为 cassandra 的瓶颈?

python - WriteToText 在 DirectRunner 中工作,但在 DataflowRunner 中因 TypeError 而失败

linux - 多节点连接管理