1. 程式人生 > >hive-shell批量命令執行指令碼

hive-shell批量命令執行指令碼

#!/usr/bin/bash
HADOOP_HOME="/opt/module/cdh-5.3.6-ha/hadoop-2.5.0-cdh5.3.6"
HIVE_HOME='/opt/module/cdh-5.3.6-ha/hive-0.13.1-cdh5.3.6'

####### execute hive ######

sql=$(cat <<!EOF
use db_01;
drop table dept_nopart;
create table IF NOT EXISTS dept_part(
deptno int,
dname string,
loc string
)
partitioned by (day string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
; !EOF) ############ execute begin ########### echo $sql cd $HIVE_HOME bin/hive -e "$sql" cd $HADOOP_HOME bin/hdfs dfs -mkdir -p /hive/warehouse/db_01.db/dept_part/day=20150913 ; bin/hdfs dfs -put /opt/data/dept.txt /hive/warehouse/db_01.db/dept_part/day=20150913 ; cd $HIVE_HOME bin/hive -e "use db_01;msck repair table dept_part;"
exitCode=$? if [ $exitCode -ne 0 ];then echo "[ERROR] hive execute failed!" exit $exitCode fi