#!/bin/bash # cd `dirname $0` BIN_DIR=`pwd` export JAVA_HOME=/usr/jdk/jdk1.8.0_201 # es目录是/usr/local/elk/elasticsearch/elasticsearch-7.12.0/bin ES_ID=`ps -ef |grep elasticsearch |grep -w 'elasticsearch'|grep -v 'grep'|awk '{print $2}'` #启动脚本目录 StartES=/usr/local/elk/elasticsearch/elasticsearch-7.12.0/bin/elasticsearch # 日志输出 ESMonitorLog=$BIN_DIR/es-monitor.log Monitor() { if [[ $ES_ID != "" ]];then # 这里判断ES进程是否存在 kill -9 $ES_ID sleep 3 sh $StartES -d fi } Monitor>>$ESMonitorLog crontab -e 10 8 * * * sh /home/esroot/es_start.sh 2>&1 10 13 * * * sh /home/esroot/es_start.sh 2>&1