Skip to content

Instantly share code, notes, and snippets.

@NeoBlack
Last active August 29, 2015 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeoBlack/0ca46373c89b6754f300 to your computer and use it in GitHub Desktop.
Save NeoBlack/0ca46373c89b6754f300 to your computer and use it in GitHub Desktop.
shell script to remove functional test databases.
#!/bin/bash
################################################################################
# Cleanup databases after functional test runs
#
# call for a check:
# ./cleanupFunctionalTestDatabases.sh
# call for really delete databases:
# ./cleanupFunctionalTestDatabases.sh doit
################################################################################
################################################################################
# Settings
################################################################################
# prefix for functional test databases
DB_STARTS_WITH="t3_"
# mysql username
MUSER="root"
# mysql password
MPWD=""
# mysql command
MYSQL="mysql"
################################################################################
# Main script, no change after this line
################################################################################
clear;
DBS="$($MYSQL -u$MUSER -p$MPWD -Bse 'show databases')"
FOUND=0
for db in $DBS; do
if [[ "$db" == $DB_STARTS_WITH* ]]; then
FOUND=1
echo "Would delete $db"
if [[ $1 == "doit" ]]; then
echo "Delete database: $db";
$MYSQL -u$MUSER -p$MPWD -Bse "drop database $db";
fi
fi
done
if [[ $FOUND == 1 ]]; then
if [[ $1 != "doit" ]]; then
echo "Really delete? append 'doit' as first argument";
fi
else
echo "No databases found";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment