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

afdcj2ne  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(624)

我正在尝试使用shell脚本执行一些impala查询。如果impala查询失败,我想捕获错误消息并将其写入文本文件。
有没有办法捕获错误消息?不仅是可以使用“$?”访问的退出状态,还有impala给出的实际错误消息。
任何帮助都将不胜感激。谢谢您。

aurhwmvo

aurhwmvo1#

演示

$ 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

相关问题