Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在寻找一种取消引用python命令调用中包装的bash var的方法_Python_Linux_Bash_Amazon Web Services_Emr - Fatal编程技术网

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

正在寻找一种取消引用python命令调用中包装的bash var的方法,python,linux,bash,amazon-web-services,emr,Python,Linux,Bash,Amazon Web Services,Emr,我正在试图找到一种取消引用goldenClusterID的方法,以便在AWS CLI命令中使用它来终止我的群集。此程序用于补偿每天生成的动态作业流编号,以便通过计划正常关闭数据管道。我可以一整天都使用os.system(“更少的goldensclusterid”),它给了我正确的答案。然而,它不会放弃一个直接的参考建议的好东西吗 from __future__ import print_function import json import urllib import boto3 import

我正在试图找到一种取消引用goldenClusterID的方法,以便在AWS CLI命令中使用它来终止我的群集。此程序用于补偿每天生成的动态作业流编号,以便通过计划正常关闭数据管道。我可以一整天都使用os.system(“更少的goldensclusterid”),它给了我正确的答案。然而,它不会放弃一个直接的参考建议的好东西吗

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()
system(“aws emr描述集群——集群id%s”%goldkeyID)

将Python用于看起来非常像Bash脚本的东西似乎很奇怪。否则
打开(“goldenClusterID”).read()
。您要查找的
goldenClusterID
是一个文件。@F.X.通常,我只会使用BASH并设置一个cron来运行它,但是,它必须包含在AWS Lambda中,带有它的调度程序,因此,我从AWS中选择的内容不能直接包含BASH。因此用python将其包装起来。