Skip to content

Instantly share code, notes, and snippets.

@pipizhang
Last active March 29, 2018 20:37
Show Gist options
  • Select an option

  • Save pipizhang/964220f5295656d1bc63da0c41e402b3 to your computer and use it in GitHub Desktop.

Select an option

Save pipizhang/964220f5295656d1bc63da0c41e402b3 to your computer and use it in GitHub Desktop.
Send MySQL slow query report to email
#!/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