记录一些随笔的实用的小脚本
1.Python 调用linux指令
使用python脚本,调用linux系统输出命令自动化执行hql
背景:此行为需要在有hive的权限已经开通的环境中
#-*- coding:utf-8 -*-
# @Time : 2020/11/4 22:45
# @File : __init__.py.py
import commands
file_path="/tmp/script/table.log"
file_path_w="/tmp/xdsp/script/table_out.log"
# 打开清单输入流
fp=open(file_path,"r")
readlines=fp.readline()
# 打开结果输出流
result_file=open(file_path_w,"wb+")
for line in readlines:
getoutput=commands.getoutput('beeline --outputformat=dsv -e "show create table '+line+'"')
if getoutput.__contains__("PARTITIONED BY"):
print "===="+line+" partition table======"
result_file.write(line)
else:
print "===="+line+" is not partition table ====="