正在寻找一种方法来取消对包装在python命令中的bash var的引用

2024-06-16 09:35:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在试图找到一种取消引用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 *")

Tags: thefromimportawsidossystemclusters
1条回答
网友
1楼 · 发布于 2024-06-16 09:35:53

没关系,我想出来了。咖啡太多,睡眠不足。答案是使用: goldkeyID=open('goldenClusterID','r').read() os.system(“aws emr描述群集id%s”%goldkeyID)

相关问题 更多 >