vi checkslave.sh
#!/bin/sh
# Slave Check status
mySQLstatus=`mysql -hlocalhost -ukiran -pkiran@123 -e"show slave status\G" | grep 'Slave_SQL_Running' | awk '{print $2}'`
myIOstatus=`mysql -hlocalhost -ukiran -pkiran@123 -e"show slave status\G" | grep 'Slave_IO_Running' | awk '{print $2}'`
error=`mysql -hlocalhost -ukiran -pkiran@123 -e "show slave status \G" | grep 'Last_IO_Error'`
if [[ $mySQLstatus = 'No' && $myIOstatus = 'No' ]]; then
oneFail="Slave WC `hostname` is stopped"
elif [[ $mySQLstatus = 'Yes' && $myIOstatus != 'Yes' ]]; then
oneFail="Slave SQLIO Status on WC `hostname` is stopped"
elif [[ $mySQLstatus != 'Yes' && $myIOstatus = 'Yes' ]]; then
oneFail="Slave SQL Status on WC `hostname` is stopped"
fi
if [[ $mySQLstatus != 'Yes' || $myIOstatus != 'Yes' ]]; then
echo "slave has been stopped"
echo "$oneFail"
echo "$error"
#echo "$oneFail $error"
echo "$oneFail" > myfile.txt
echo "$error" | sed -e 's/^[ \t]*//' >> myfile.txt
#echo "$oneFail `\n` $error" | mail -s "mysql slave error `hostname`" kiran.chinta@gmail.com
cat myfile.txt | mail -s "mysql slave error `hostname`" kiran.chinta@gmail.com

No comments:
Post a Comment