python自动生成执行集群操作脚本

外部转入参数,循环列表生成脚本,并执行:


#!/usr/bin/python
#
import sys
import os


list=['2016-06-07','2016-06-08','2016-06-09','2016-06-10','2016-06-11','2016-06-12','2016-06-13']

for d in list:
    cmd='hadoop distcp hftp://hadoop2:50070/user/datamart/adobe/adobe.'+sys.argv[1]+'/'+d+' /user/hive/warehouse/adobe.db/'+sys.argv[2]+'/load_day='+d
    print cmd
    os.system(cmd)

for d in list:
    cmd='hive -e"alter table adobe.'+sys.argv[2]+' add partition(load_day=\''+d+'\') location \'/user/hive/warehouse/adobe.db/'+sys.argv[2]+'/load_day='+d+'\';"'
    print cmd
    os.system(cmd)

print 'ok'


后台执行脚本:
nohup python distcpData.py ADOBE_NWD_PRD adobe_nwd_prd > prd.log &


你可能感兴趣的:(Linux)