我正在尝试使用shell脚本执行一些impala查询。如果impala查询失败,我想捕获错误消息并将其写入文本文件。
有没有办法捕获错误消息?不仅可以使用' $?'来访问退出状态,还可以使用impala给出的实际错误消息。
任何帮助将不胜感激。谢谢。
答案 0 :(得分:1)
$ 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