Support Questions

Find answers, ask questions, and share your expertise

Return code for beeline command in shell script

avatar

How to capture the return code of the Beeline command that I am executing within a Shell Script. Like Below:

beeline -u $Beeline -e "ALTER TABLE DROP if exists partition (date='');"

I want to capture the status of above query with in shell script.

Thanks AG

1 REPLY 1

avatar

Hi @Atul Goel!
Did you try the following command?

[hive@node3 ~]$ beeline -u 'jdbc:hive2://node2:2181,node3:2181,node4:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' --showNestedErrs --showWarnings --verbose -e "select 1 + 1;" 2> /tmp/beeline.out
[hive@node3 ~]$ cat /tmp/beeline.out 
issuing: !connect jdbc:hive2://node2:2181,node3:2181,node4:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2 '' [passwd stripped] 
Connecting to jdbc:hive2://node2:2181,node3:2181,node4:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Executing command: select 1 + 1;
Getting log thread is interrupted, since query is done!
1 row selected (0.218 seconds)
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
Closing: 0: jdbc:hive2://node2:2181,node3:2181,node4:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

Hope this helps!