我编写了一个
shell脚本,它在杀死/终止时启动
MySQL.我正在使用crontab运行此shell脚本.
我的cron在/root/mysql.sh下查找名为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:
# mysql root/admin username
MUSER="xxxx"
# mysql admin/root password
MPASS="xxxxxx"
# mysql server hostname
MHOST="localhost"
MSTART="/etc/init.d/mysql start"
# path mysqladmin
MADMIN="$(which mysqladmin)"
# see if MySQL server is alive or not
# 2&1 could be better but i would like to keep it simple
$MADMIN -h $MHOST -u $MUSER -p${MPASS} ping 2>/dev/null 1>/dev/null
if [ $? -ne 0 ]; then
# MySQL's status log file
MYSQL_STATUS_LOG=/root/validate-mysql-status/mysql-status.log
# If log file not exist, create a new file
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
# Restarting MySQL
/etc/init.d/mysql start
now1="$(date)"
echo [$now1] info : MySQL started >> $MYSQL_STATUS_LOG
cat $MYSQL_STATUS_LOG
fi
当我使用webmin的crontab手动运行上面的mysql shell脚本时,MySQL启动成功(当它被杀死时).
但是,当我使用cron作业安排它时,MySQL无法启动.日志打印正确(这意味着我的cron成功运行预定脚本,但MySQL没有重新启动).
crontab -l显示:
* * * * * sh /root/mysql.sh
我从URL中发现,我们应该给出通过调度程序如cron重启MySQL的绝对路径.但是,它对我没用.
谁能帮帮我吗!
谢谢.