Skip to content

Instantly share code, notes, and snippets.

@prateek
Last active August 29, 2015 14:18
Show Gist options
  • Save prateek/8cabbb3629b348db0dc3 to your computer and use it in GitHub Desktop.
Save prateek/8cabbb3629b348db0dc3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# paranoia with shell scripts, always to be encouraged
set -e
LOG=/tmp/shell-impala-$USER-$(date +%s).log
# echo-ing params to find logs on local fs in case of error
echo "HOST: ${HOSTNAME}"
echo "LOG: ${LOG}"
if [ $# -ne 4 ];
then
ERROR="Usage: $0 <keytab-file> <kerberos-principal> <query-file> <impalad_host:impalad_port>"
echo "$ERROR"
echo "$ERROR" >> ${LOG}
exit 1
fi
KEYTAB=$1
PRINCIPAL=$2
QUERY_FILE=$3
CONN_PARAM=$4
export PYTHON_EGG_CACHE=./myeggs
if [ ! -f $KEYTAB ];
then
ERROR="Unable to access [ keytab-file: $KEYTAB ], check existence and permissions"
echo "$ERROR"
echo "$ERROR" >> ${LOG}
exit 2
fi
if [ ! -f $QUERY_FILE ];
then
ERROR="Unable to access [ query-file: $QUERY_FILE ], check existence and permissions"
echo "$ERROR"
echo "$ERROR" >> ${LOG}
exit 3
fi
# redirecting both stderror and stdout to append to the log-file
/usr/bin/kinit -kt $KEYTAB -V "$PRINCIPAL" >>${LOG} 2>&1
/usr/bin/klist -e >>${LOG} 2>&1
impala-shell -k -i $CONN_PARAM -f $QUERY_FILE >>${LOG} 2>&1
RC=$?
if [ $RC -ne 0 ];
then
echo "Impala-shell did not finish successfully, [ rc = $RC ]" >>${LOG}
hadoop fs -put ${LOG} /tmp
# indicating error so shell action fails in Oozie
exit 4
fi
hadoop fs -put ${LOG} /tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment