#!/bin/bash
#PATH=/bin:/usr/bin:/sbin:/usr/local/bin
# cronjob need clear where is the path
# mysql under path /usr/local/bin
mysql --host="localhost" --user="gts" --password="opengts" --database="gts" --execute="select deviceID from Device limit 1"
if [ $? -eq 0 ]; then echo "";
# mysql run well nothing to do, make a
else
 #service mysqld stop
 #pkill /usr/local/bin/mysql
# It should be pkill /usr/local/bin/mysql, not pkill mysql, wrong write will cause below code not working
 /sbin/service mysqld start
echo -e "MYSQL-Stopped (Opting for Auto-restart Mode)" 2>&1 | sed '1!b;s/^/To: anudeep@glovision.co,support@glovision.co\nSubject: [UP102EAST-SERVER]MYSQL-Stopped\n\n/' | /usr/sbin/sendmail -t
 #/etc/init.d/httpd restart
# Some strange behave, after mysql restart, apache will die, so should add httpd restart 
 #echo "error $(date)" >> /home/myspace/restart_log.txt
fi

