vim xxx.sh
#!/bin/bash
count=`ps -ef| grep service-name | grep -v "grep" | wc -l `
echo "count: "$count", time: "$(date "+%Y-%m-%d %H:%M:%S");
if [ $count == 0 ]; then
service service-name start ;
fi
保存
crontab -e 编辑定时任务
*/5 * * * * sh /paht/xxx.sh >> /var/log/xxx.log // 每5分钟执行一次