Last active
December 4, 2018 20:51
-
-
Save colinmollenhour/6578ac005074bd2f992e to your computer and use it in GitHub Desktop.
Record all new deadlocks in separate files
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 | |
# | |
# Copyright Colin Mollenhour 2014 | |
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