Shell Script to Check the Status of MySQL Replication

#!/bin/bash
emailAddress="emailtoNotify@domain.com"
cmd=`mysql -e 'show slave status\G' | grep Slave_SQL_Running | awk '{print $2}'`
if [ "$cmd" == "No" ];then         MSG="Mysql Replication Broken on `hostname`, please check asap"         echo $MSG | mail -s "Replication Broken on `hostname`" $emailAddress
fi

If you want to get the value of check to be 0 or 1 you can use the following :

mysql -e 'show slave status\G' | grep Slave_SQL_Running | awk '{print $2}' | sed 's/No/0/;s/Yes/1/'