使用Spark-submit提交Spark任务封装shell脚本
if [ $
spark-submit --master local[4] --class hx.com.Ods2DwdFilterSql --files /home/etl_admin/spark/config.properties sparkDwdFilter-1.0-SNAPSHOT.jar $1
else
echo "Please input command. eg: ./$0 filename.sql(hql)"
fi
if [ $
spark-submit \
--master yarn \
--deploy-mode client \
--queue default \
--driver-memory 2g \
--num-executors 3 \
--executor-memory 2g \
--executor-cores 2 \
--class hx.com.Ods2DwdFilterSql \
--files /home/etl_admin/spark/config.properties \
sparkDwdFilter-1.0-SNAPSHOT.jar /opt/etl/sqlFiles/$1
else
echo "Please input command. eg: ./$0 filename.sql(hql)"
fi
if [ $
spark-submit \
--master yarn \
--deploy-mode cluster \
--queue default \
--driver-memory 2g \
--num-executors 3 \
--executor-memory 2g \
--executor-cores 2 \
--class hx.com.Ods2DwdFilterSql \
--files /home/etl_admin/spark/config.properties \
sparkDwdFilter-1.0-SNAPSHOT.jar /opt/etl/sqlFiles/$1
else
echo "Please input command. eg: ./$0 filename.sql(hql)"
fi
shell脚本创建hbase表
[[ $
hbase_table="'$1'"
cf="'f'"
echo "输入的hbase表 ==> $hbase_table $cf"
echo `hbase shell <<EOF
exists $hbase_table
EOF` |grep 'does exist'
status=$?
echo "exists ? ==> status=$status"
if [ $status -eq 0 ];then
echo "table exists..."; exit 0
fi
echo "table not exists ! ===> start creating...."
hbase shell <<EOF
create $hbase_table , $cf
EOF
status=$?
if [ $status -eq 0 ];then
echo "create succeed ! "
else
echo "error,create not done !"
fi
批量导出hive表
DATABASES='gmall'
for DATABASE in ${DATABASES}
do
hive -e "use ${DATABASE}; show tables;" > ${DATABASE}_tables.txt
sed -i '/WARN:/d' ${DATABASE}_tables.txt
echo "use ${DATABASE};" >> ${DATABASE}_repair_tables.sql
echo "set hive.msck.path.validation=ignore;" >> ${DATABASE}_repair_tables.sql
echo "use ${DATABASE};" >> ${DATABASE}_count.sql
cat ${DATABASE}_tables.txt | while read eachline
do
hive -e "use ${DATABASE}; show create table ${eachline};" >> ${DATABASE}_tables_ddl.sql
echo "msck repair table ${DATABASE}.${eachline};" >> ${DATABASE}_repair_tables.sql
echo "select count(1) from ${DATABASE}.${eachline} union all " >> ${DATABASE}_count.sql
done
sed -i '/WARN:/d' ${DATABASE}_tables_ddl.sql
sed -i "s/\`/ /g" ${DATABASE}_tables_ddl.sql
cat ${DATABASE}_tables.txt | while read eachtable
do
sed -i "s/CREATE EXTERNAL TABLE ${eachtable}/;CREATE EXTERNAL TABLE ${DATABASE}.${eachtable}_bak/g" ${DATABASE}_tables_ddl.sql
done
echo ";" >> ${DATABASE}_tables_ddl.sql
done