我必须以直线方式自动化一些活动,就像我们在hivecli中所做的一样。下面是配置单元自动化任务的运行示例shell脚本:
echo "using new_db HIVE database..!!"
hive -e "use new_db;"
echo "truncating the staging table test..."
hive -e "TRUNCATE TABLE new_db.test;"
echo "Loading the data into the staging table test"
hive -e "LOAD DATA LOCAL INPATH '/<path>/IDI.txt' INTO TABLE new_db.test;"
echo "Appending the data into history table hist_test.."
hive -e "insert into table new_db.test select *, '$unix_time' from new_db.test;"
我想做一个类似的事情直线。我是直线的初学者。所以我想出了如下的办法。
# ! /bin/bash
timestamp=$(date +%Y-%m-%d-%H:%M:%S:%N)
unix_time=$(date +%Y-%m-%d-%H:%M:%S)
echo "Login to BeeLine..!!"
# beeline << EOF
beeline -u jdbc:hive2://server:port,server:port,server:port/;serviceDiscoveryMode=zookeeper;zookeeperNamespace=hiveserver2;principal=hive/server@hello.COM<< EOF -n <username> -p <password>
echo "using new_db HIVE database..!!"
beeline -e "use new_db;"
echo "truncating the staging table test..."
beeline -e "TRUNCATE TABLE new_db.test;"
echo "Loading the data into the staging table test"
beeline -e "LOAD DATA LOCAL INPATH '/<path>/IDI.txt' INTO TABLE new_db.test;"
echo "Appending the data into history table hist_test.."
beeline -e "insert into table new_db.test select *, '$unix_time' from new_db.test;"
EOF
++++++++++++++++++++++++++
新语法
# ! /bin/bash
export BEELINE_PREFIX="jdbc:hive2://server:port,server:port,server:port/;serviceDiscoveryMode=zookeeper;zookeeperNamespace=hiveserver2;principal=hive/server@hello.COM"
export FILE_PATH="path_toFile/staging_hive_tables.hql"
beeline -u $BEELINE_PREFIX -f $FILE_PATH
1条答案
按热度按时间vptzau2j1#
像这样试试。
编辑1:
双引号不见了。。用单引号将直线前缀括起来试试这个
编辑2:
我在命令提示符下运行了这些
注意,您需要回显命令并将其传递给shell(sh)
echo“beeline-u${beeline_prefix}-f/tmp/hive1.ql”| sh-x