I wrote a shell script that starts MySQL when it is killed / terminated. I am running this shell script using crontab.
My cron is looking for a script file named mysql.sh under /root/mysql.sh
sh /root/mysql.sh
mysql.sh:
cd /root/validate-mysql-status
sh /root/validate-mysql-status/validate-mysql-status.sh
validate-mysql-status.sh:
MUSER="xxxx"
MPASS="xxxxxx"
MHOST="localhost"
MSTART="/etc/init.d/mysql start"
MADMIN="$(which mysqladmin)"
$MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]; then
MYSQL_STATUS_LOG=/root/validate-mysql-status/mysql-status.log
if [ ! -f $MYSQL_STATUS_LOG ]; then
cat "Creating MySQL status log file.." > $MYSQL_STATUS_LOG
now="$(date)"
echo [$now] error : MySQL not running >> $MYSQL_STATUS_LOG
else
now="$(date)"
echo [$now] error : MySQL not running >> $MYSQL_STATUS_LOG
fi
/etc/init.d/mysql start
now1="$(date)"
echo [$now1] info : MySQL started >> $MYSQL_STATUS_LOG
cat $MYSQL_STATUS_LOG
fi
When I run the above mysql script shell manually using webmin crontab, MySQL started successfully (when it was killed).
However , when I plan to use it with the cron job, MySQL does not start. Logs print correctly (this means that my cron runs the scheduled script successfully, but MySQL does not restart).
crontab -l displays:
* * * * * sh /root/mysql.sh
URL-, MySQL , cron. , .
- !
.
user915303