Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement