Created
April 25, 2018 08:20
-
-
Save colinmollenhour/38777d42da9003fdf25eca56b9fc5640 to your computer and use it in GitHub Desktop.
Log Innodb Deadlocks
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 | |
dir=/root/deadlocks | |
[ -d $dir ] || mkdir -p $dir | |
cd $dir || { echo "Could not cd to $dir"; exit 1; } | |
mysql -be 'show engine innodb status;' \ | |
| sed 's/\\n/\n/g' \ | |
| awk '/TRANSACTIONS/{flag=0}flag;/LATEST DETECTED DEADLOCK/{flag=1}' \ | |
> latest.txt | |
filename=$(head -n 2 latest.txt | tail -n 1) | |
if [ -f previous.txt ]; then | |
diff --brief latest.txt previous.txt > /dev/null | |
if [ $? -eq 1 ]; then | |
cp latest.txt "$filename.txt" | |
fi | |
else | |
cp latest.txt "$filename.txt" | |
fi | |
mv latest.txt previous.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment