方式一:创建shell脚本hive1.sh:,通过传参导出指定库的表结构:
#!/bin/bash
DATABASE=$1
hive -e “use ${DATABASE}; show tables;” > ${DATABASE}_tables.txt
sleep 1
cat ${DATABASE}_tables.txt | while read eachline
do
hive -e “show create table ${eachline};” >> ${DATABASE}_tables.txt
done
方式二:在脚本里面定义要导出的hive库,通过循环遍历
#!/bin/bash
DATABASES=‘db1 db2 db3’
for DATABASE in ${DATABASES}
do
hive -e “use ${DATABASE}; show tables;” > ${DATABASE}_tables.txt
sleep 1
cat ${DATABASE}_tables.txt | while read eachline
do
hive -e “show create table ${eachline};” >> ${DATABASE}_tables.txt
done
done
另外,
hive 参数 -s :为不输出日志,hive -e 可执行多条sql,并且sql用分号";"结尾