Skip to content

Instantly share code, notes, and snippets.

@colinmollenhour
Last active December 4, 2018 20:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinmollenhour/6578ac005074bd2f992e to your computer and use it in GitHub Desktop.
Save colinmollenhour/6578ac005074bd2f992e to your computer and use it in GitHub Desktop.
Record all new deadlocks in separate files
#!/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