Created
March 14, 2014 11:44
-
-
Save malias/caab4feae06c7da0be57 to your computer and use it in GitHub Desktop.
Find Big Tables
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 | |
# Description: Find Tables bigger than 2GB | |
# to clean up | |
# Global variables | |
TmpLog='/tmp/mysql_table.log' | |
# E-Mail recipients (multiple mail addresses separated by whitespace) | |
email='' | |
# InnoDB Table Files | |
Path='/var/lib/mysql/' | |
# Test TmpLog and create | |
test -f $TmpLog && rm $TmpLog && touch $TmpLog | |
# Find Tables bigger than 2GB | |
find $Path -type f -size +2G \( -name "*.ibd" -o -name "*.MYD" \) -exec du -h {} \; | sort -h -r >> $TmpLog | |
# Send notification | |
send_mail(){ | |
# Check tempfile is empty | |
if [ -s $TmpLog ]; then | |
# Use mailadress(es) from variable | |
for mailaddress in $email; do | |
# Send mail with log output | |
mail -s "Table size check $(hostname)" $mailaddress < $TmpLog | |
done | |
fi | |
} | |
# Execute mail function | |
send_mail | |
# End with Return Code | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment