#!/bin/bash result=`/usr/bin/mysqladmin ping`expected='mysqld is alive' if [[ "$result" != "$expected" ]]thenecho "It's dead - restart mysql" # email subjectSUBJECT="[MYSQL ERROR] - Attempting to restart service" # Email To ?EMAIL="info@endyourif.com" # Email text/messageEMAILMESSAGE="/tmp/emailmessage.txt"echo "$result was received"> $EMAILMESSAGEecho "when we were expected $expected" >>$EMAILMESSAGE# send an email using /bin/mailmail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE sudo /etc/init.d/mysql restartfi