Shell Script to Start Mysql Server if not running
- by user103373
I have written a shell script to start mysql server & send a mail to admin user if it's restarted via shell script. What i am facing an issue if I run this shell script on terminal it's work perfectly & If same script runs via cronjob it's only sending the mail to the user & problem remains same. Is this problem relates to permission & how can i resolve it.
Shell Script--------
#!/bin/bash
EMAIL="[email protected]"
SERVICE='mysql'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
echo "$SERVICE is not running"
/etc/init.d/mysql start
cat <<EOF | msmtp -a gmail $EMAIL
Subject: "Alert (Test Server) : Mysql Service is not running (Manually Restarted)"
Mysql Server Restarted at: `date`
EOF
EXIT
I am using msmtp for sending mail to the user on ubuntu 12.04 Server.