Shell Script to Start Mysql Server if not running
Posted
by
user103373
on Server Fault
See other posts from Server Fault
or by user103373
Published on 2012-09-19T05:23:23Z
Indexed on
2012/09/19
9:41 UTC
Read the original article
Hit count: 200
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.
© Server Fault or respective owner