Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created July 13, 2009 06:01
Show Gist options
  • Select an option

  • Save itspriddle/145961 to your computer and use it in GitHub Desktop.

Select an option

Save itspriddle/145961 to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
cat <<-EOT
usage: $0 options
Options:
-u Username
-p Password
-d Create database
EOT
}
DB=0
while getopts 'u:p:d' OPTION
do
case $OPTION in
u) USER=$OPTARG
;;
p) PASS=$OPTARG
;;
d) DB=1
;;
esac
done
if [ "$USER" = "" ] || [ "$PASS" = "" ]; then
usage
exit 1
fi
groupadd $USER
useradd -m -g $USER -s /bin/bash -p $PASS $USER
if [ $DB == 1 ]; then
mysqladmin create $USER
mysql -e "grant all privileges on $USER.* to $USER@localhost identified by '$PASS'"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment