#!/bin/sh ###Alert if Query is Hung### # Created by Will Mayall wamayall@yahoo.com # 30-SEP-2011 connections=$(echo "show full processlist\G" | mysql -ugpm | grep "Time: " | sort -r | sed -e s/Time://g |awk '{print $1}') for total_seconds in $connections do if [ $total_seconds -gt 10000 ]; then echo "Query is Hung" > /home/wmayall/scripts/HUNG_QUERY.txt fi done ###Send notification if Query is Hung### #cd /home/wmayall/scripts if [ -f HUNG_QUERY.txt ]; then mail -s "Query is Hung" admin@example.com < /home/wmayall/scripts/HUNG_QUERY.txt fi