Skip to content

Instantly share code, notes, and snippets.

@cjmatta
Last active February 4, 2016 15:22
Show Gist options
  • Save cjmatta/93993f9283c3508c18d6 to your computer and use it in GitHub Desktop.
Save cjmatta/93993f9283c3508c18d6 to your computer and use it in GitHub Desktop.
A wrapper script for Drill's sqlline that asks for user/pass to avoid the password showing up in a process list.
#!/bin/bash
USERNAME=
PASSWORD=
DRILL_VER=drill-1.4.0
DRILL_LOC=/opt/mapr/drill
URL=jdbc:drill:
DPROP=~/prop$$
touch $DPROP
chmod 600 $DPROP
usage () {
echo "$0 [ -u|--user username ]"
}
ask_user () {
printf "Enter username: "
read USERNAME
}
ask_pass () {
stty -echo
printf "Enter password for ${USERNAME}: "
read PASSWORD
stty echo
printf "\n"
}
while :; do
case $1 in
-h|-\?|--help)
usage
exit
;;
-u|--user)
if [ -n "$2" ]; then
USERNAME=$2
shift
else
printf 'ERROR: "--user" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--user=?*)
USERNAME=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: If no more options then break out of the loop.
break
esac
shift
done
if [[ -z $USERNAME ]];
then
ask_user
fi
if [[ -z $PASSWORD ]];
then
ask_pass
fi
# Write properties file for Drill
cat >> $DPROP <<!
user=$USERNAME
password=$PASSWORD
url=$URL
!
# Exectue Drill connect with properties file. After 5 seconds, the command
# will delete the prop file. Note this may result in race condition.
# 5 seconds SHOULD be enough.
(sleep 5; rm $DPROP) & $DRILL_LOC/$DRILL_VER/bin/sqlline $DPROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment