Cronjob email

Linux

!/bin/bash

HOST=your-server-ip
USER=mysql-user
PASSWORD=mysql-password
SUBJECT=”Mysql replication problem”
[email protected]

RESULT=mysql -h $HOST -u$USER -p$PASSWORD -e 'show slave status\G' | grep Last_SQL_Error | sed -e 's/ *Last_SQL_Error: //'
if [ -n “$RESULT” ]; then
echo “$RESULT” | mail -s “$SUBJECT” $EMAIL
fi


!/bin/bash

host=my.db.com
user=repl_check
password=xxxx

MSG=mysql -h $host -u$user -p$password -e 'show slave status\G' | grep Last_SQL_Error | sed -e 's/ *Last_SQL_Error: //'
if [ -n “$MSG” ]; then
# email someone
echo $MSG | mailx -s “MySQL Replication error” [email protected]
fi