SHARE
TWEET

Untitled

a guest Feb 4th, 2016 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. USERNAME=
  4. PASSWORD=
  5.  
  6. DRILL_VER=drill-1.4.0
  7. DRILL_LOC=/opt/mapr/drill
  8. URL=jdbc:drill:
  9.  
  10. DPROP=~/prop$$
  11.  
  12. touch $DPROP
  13. chmod 600 $DPROP
  14.  
  15. usage () {
  16.     echo "$0 [ -u|--user username ]"
  17. }
  18.  
  19. ask_user () {
  20.     printf "Enter username: "
  21.     read USERNAME
  22. }
  23.  
  24. ask_pass () {
  25.     stty -echo
  26.     printf "Enter password for ${USERNAME}: "
  27.     read PASSWORD
  28.     stty echo
  29.     printf "\n"
  30. }
  31.  
  32. while :; do
  33.     case $1 in
  34.         -h|-\?|--help)
  35.             usage
  36.             exit
  37.             ;;
  38.         -u|--user)
  39.             if [ -n "$2" ]; then
  40.                 USERNAME=$2
  41.                 shift
  42.             else
  43.                 printf 'ERROR: "--user" requires a non-empty option argument.\n' >&2
  44.                 exit 1
  45.             fi
  46.             ;;
  47.         --user=?*)
  48.             USERNAME=${1#*=} # Delete everything up to "=" and assign the remainder.
  49.             ;;
  50.         --)              # End of all options.
  51.             shift
  52.             break
  53.             ;;
  54.         -?*)
  55.             printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
  56.             ;;
  57.         *)               # Default case: If no more options then break out of the loop.
  58.             break
  59.     esac
  60.  
  61.     shift
  62. done
  63.  
  64. if [[ -z $USERNAME ]];
  65. then
  66.     ask_user
  67. fi
  68.  
  69. if [[ -z $PASSWORD ]];
  70. then
  71.     ask_pass
  72. fi
  73.  
  74. # Write properties file for Drill
  75. cat >> $DPROP <<!
  76. user=$USERNAME
  77. password=$PASSWORD
  78. url=$URL
  79. !
  80.  
  81. # Exectue Drill connect with properties file. After 5 seconds, the command
  82. # will delete the prop file. Note this may result in race condition.
  83. # 5 seconds SHOULD be enough.
  84. (sleep 5; rm $DPROP) & $DRILL_LOC/$DRILL_VER/bin/sqlline $DPROP
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top