特定执行前缀
#!/usr/bin/env python
# coding=utf-8
# -*- coding=utf-8
获取命令行结果
import os
command = 'pwd' #可以直接在命令行中执行的命令
r = os.popen(command) #执行该命令
info = r.readlines() #读取命令行的输出到一个list
for line in info: #按行遍历
line = line.strip('\r\n')
print(line)
批量关闭指定的Yarn资源
import os
res_dic = {}
command = 'yarn application -list'
r = os.popen(command)
info = r.readlines()
for line in info:
line = line.strip('\r\n')
line_item = line.split("\t")
if len(line_item) >= 2:
target_str_index = line_item[1].find('Hive on Spark')
if target_str_index != -1:
print("yarn application -kill " + line_item[0])
os.popen("yarn application -kill " + line_item[0])