I am executing a Hive query via beeline from a shellscript. Below is a sample of the code: I see that even if connection to Hive Database fails, $? would still return zero as exit code. How can I fetch the exit code/connectivity status from beeline for a use case like below ? I need to stop the execution of shellscript as soon as beeline fails to connect to DB and a proper message should be logged suggesting Hive Connection failed.
beeline -u $HIVE_CONNECTION_STRING --outputformat=csv2 -f $LOCATION_OF_HIVE_SELECT_QUERY_FILE > QueryResults.csv
if [$? -ne 0]; then
echo "Could not connect to DB."
exit 1
else
#Do rest of the process since data was fetched from DB successfully above
fi