以mysql为例,先上shell脚本,如下:
    #!/bin/bash
    ps -ef | grep mysqld | grep -v grep
    if [ $? -ne 0 ]
    then
    echo “start process……”
    /etc/rc.d/init.d/mysqld start
    else
    echo “runing……”
    fi

    保存脚本,手动运行一下,确保没有错误。

    执行crontab -e,来进入定时设置:
    crontab -e
    8,18 /test/test.sh
    这里设置每天的上午8点到下午6点之间每分钟执行一次脚本
    /test/test.sh 是shell脚本的绝对路径
    设置好后重启crontab服务,命令如下
    service crond restart
    设置完成!
    查看邮件了解脚本定时执行的情况:
    mail