gpt4 book ai didi

bash - 如何从bash shell脚本运行beeline和hive查询

转载 作者:行者123 更新时间:2023-12-02 19:44:00 27 4
gpt4 key购买 nike

登录到unix bash shell后,我可以按顺序手动运行以下步骤。

echo "Connecting beeline" 

beeline
!connect jdbc:hive2://a301-1234-1234.stm.XXX.com:10000/default;;ssl=true;sslTrustStore=/app/bds/cloudera_truststore.jks;sslTrustPassword=;principal=hive/_HOST@BDS.XXXX.COM

INSERT OVERWRITE DIRECTORY "/dev/ref/HIVE_EXPORT/" ROW FORMAT DELIMITED FIELDS TERMINATED BY "," ESCAPED BY "\\" SELECT * FROM test_ref_st.Daily_report limit 10;

hadoop fs -get('/dev/ref/HIVE_EXPORT/000000_0', '/user/rj/hiveExtract.csv')
echo "Query result extracted "
我需要通过shell脚本test1.sh依次运行上述所有步骤
bash-4.2$ sh -x test1.sh
然后它将一直运行,直到beeline和其余命令未运行为止。
电流输出:
bash-4.2$ sh test1.sh

Picked up JAVA_TOOL_OPTIONS:
Beeline version 1.1.0-cdh5.16.2 by Apache Hive
beeline>

最佳答案

Bash正在逐行处理脚本。它运行beeline并等待您的输入。
您可以使用heredoc从脚本中写入标准输入:

beeline <<EOF
!connect jdbc:hive2://a301-1234-1234.stm.XXX.com:10000/default;;ssl=true;sslTrustStore=/app/bds/cloudera_truststore.jks;sslTrustPassword=;principal=hive/_HOST@BDS.XXXX.COM
INSERT OVERWRITE DIRECTORY "/dev/ref/HIVE_EXPORT/" ROW FORMAT DELIMITED FIELDS TERMINATED BY "," ESCAPED BY "\\" SELECT * FROM test_ref_st.Daily_report limit 10;
EOF

关于bash - 如何从bash shell脚本运行beeline和hive查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62784947/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com