linux使用计划任务监控进程是否启动

      发布在:后端技术      评论:0 条评论

linux使用计划任务监控进程是否启动,如果没有启动则执行启动命令脚本

加入计划任务执行脚本,每分钟执行一次run.sh脚本:

#!/usr/bin/env bash
basepath=$(cd `dirname $0`; pwd)
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
result=$(crontab -l|grep -i "* * * * * sh $basepath/run.sh"|grep -v grep)
if [ ! -n "$result" ]
then
crontab -l > conf && echo "* * * * * sh $basepath/run.sh >/dev/null 2>&1" >> conf && crontab conf && rm -f conf
echo -e "\033[32mOk.\033[0m"
else
echo "The process has been add ."
fi

下面的就是run.sh脚本文件内容

判断进程xs-searchd是否存在,不存在则执行/bin/sh /usr/local/xunsearch/bin/xs-ctl.sh restart

#!/usr/bin/env bash
basepath=$(cd `dirname $0`; pwd)
result=$(ps -ef | grep -i xs-searchd | grep -v grep)
if [ ! -n "$result" ]
then
echo "Starting the process."
/bin/sh /usr/local/xunsearch/bin/xs-ctl.sh restart
echo -e "\033[32mOk.\033[0m"
else
echo "The process has been started ."
fi
相关文章
热门推荐