Eu faria algo como:
detected=(
mysql --defaults-extra-file=/etc/mysql/debian.cnf --raw -Be '
show engine innodb status' | perl -ln -0777 -e '
while (/(\*\*\* \(\d+\) TRANSACTION:\s+TRANSACTION \S+ ACTIVE (\d+).*?)(?=\*\*\*)/sg) {
print $1 if $2 > 100;
}'
)
if [ -n "$detected" ]; then
mailx -s "$subject" "$addresses" << EOF
Some transactions took more than 100 seconds:
$detected
EOF
fi
Para referência, o texto acima é adaptado ao formato que vejo mais parecido com:
*** (1) TRANSACTION:
TRANSACTION AE523D, ACTIVE 0 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 9 lock struct(s), heap size 1248, 4 row lock(s), undo log entries 2
MySQL thread id 40705, OS thread handle 0x7fa6d8197700, query id 5697977 localhost bugs updating
DELETE FROM tokens WHERE token = 'JpLgGK5Ygn'
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 32823 n bits 280 index 'PRIMARY' of table 'bugs'.'tokens' trx id AE523D lock_mode X locks rec but not gap waiting
Record lock, heap no 212 PHYSICAL RECORD: n_fields 7; compact format; info bits 32
0: len 10; hex 4a704c67474b3559676e; asc JpLgGK5Ygn;;
1: len 6; hex 000000ae523b; asc R;;;
2: len 7; hex 6c0000c01f0572; asc l r;;
3: len 3; hex 80000f; asc ;;
4: len 8; hex 80001255ef969792; asc U ;;
5: len 7; hex 73657373696f6e; asc session;;
6: len 17; hex 6372656174655f6174746163686d656e74; asc create_attachment;;
*** (2) TRANSACTION: