Last active
March 29, 2018 20:37
-
-
Save pipizhang/964220f5295656d1bc63da0c41e402b3 to your computer and use it in GitHub Desktop.
Send MySQL slow query report to email
This file contains hidden or 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 | |
| SLOWDUMP="/opt/mysql/bin/mysqldumpslow" | |
| EMAIL_TO="$YOUR_EMAIL" | |
| SLOWLOG_FILE="/var/log/mysql-slow.log" | |
| SLOWLOG_ALL="/var/log/mysql-slow-all.log" | |
| text=$(cat "$SLOWLOG_FILE") | |
| if [ "$text" != "" ]; then | |
| echo "find update, send mail" | |
| $SLOWDUMP $SLOWLOG_FILE | mutt -s "[BANANA] mysql slow query report" $EMAIL_TO | |
| cat $SLOWLOG_FILE >> $SLOWLOG_ALL && echo > $SLOWLOG_FILE | |
| else | |
| echo "nothing" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment