Last active
December 16, 2015 18:09
-
-
Save jeffreyroberts/5475433 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: sub mytop [-u (username)] [-p (password)] | |
# Summary: Watch MySQL Processes / Queries | |
# Help: Take a snapshot of what mysql queries are running in one second intervals | |
# Reference: http://akrabat.com/software/the-watch-linux-command-line-tool/ | |
set -e | |
# Default Username & Password | |
_MYTOP_PASSWORD="-pYOURPASSWORD" # or "" for no password | |
_MYTOP_USERNAME="-uroot" | |
while [ ! "$1" == "" ] | |
do | |
if [[ "$1" == "-p" && ! "$2" == -* && ! "$2" == "" ]]; then | |
_MYTOP_PASSWORD="-p$2" | |
elif [[ "$1" == "-p" && ! "$2" == -* && "$2" == "" ]]; then | |
echo "You must supply a password with -p flag" | |
exit | |
elif [[ "$1" == "-u" && ! "$2" == -* && ! "$2" == "" ]]; then | |
_MYTOP_USERNAME="-u$2" | |
elif [[ "$1" == "-u" && ! "$2" == -* && "$2" == "" ]]; then | |
echo "You must supply a username with -u flag" | |
exit | |
fi | |
shift | |
done | |
while : | |
do | |
sleep 1 | |
clear | |
mysqladmin $_MYTOP_USERNAME $_MYTOP_PASSWORD processlist | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment