使用 shell 脚本捕获 Impala 中的错误

问题描述 投票:0回答:2

我正在尝试使用 shell 脚本执行一些 impala 查询。如果 impala 查询失败,我想捕获错误消息并将其写入文本文件。

有没有办法捕获错误消息?不仅仅是可以使用“$?”访问的退出状态,还有 impala 给出的实际错误消息。

如有任何帮助,我们将不胜感激。谢谢你。

bash shell impala
2个回答
2
投票

演示

$ cat>myfile.sql
select 1 as col1;
select abc;
select 2 as col2;

$ impala-shell -f myfile.sql 1>myfile.txt 2>myfile.err
$ result=$?

$ echo $result 
1

$ cat myfile.txt
+------+
| col1 |
+------+
| 1    |
+------+

$ cat myfile.err
Starting Impala Shell without Kerberos authentication
Connected to quickstart.cloudera:21000
Server version: impalad version 2.5.0-cdh5.7.0 RELEASE (build ad3f5adabedf56fe6bd9eea39147c067cc552703)
Query: select 1 as col1
Fetched 1 row(s) in 0.05s
Query: select abc
ERROR: AnalysisException: Could not resolve column/field reference: 'abc'

Could not execute command: select abc

0
投票

我们如何才能捕获错误消息?

© www.soinside.com 2019 - 2024. All rights reserved.