#!/bin/bash CheckProcess() { if [ "$1" = "" ]; then return 1 fi PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l` if [ $PROCESS_NUM -eq 1 ]; then return 0 else return 1 fi } CheckPort() { if [ "$1" = "" ]; then return 1 fi PROCESS_NUM=`netstat -an | grep "$1" | wc -l` if [ $PROCESS_NUM -eq 1 ]; then return 0 else return 1 fi } while [ 1 ]; do CheckProcess "elasticsearch" Check_ELA_RET=$? CheckProcess "logstash" Check_LOG_RET=$? CheckPort 5601 Check_KIB_RET=$? if [ $Check_ELA_RET -eq 1 ]; then /home/elk/elasticsearch-6.2.4/bin/elasticsearch -d elif [ $Check_LOG_RET -eq 1 ]; then /home/elk/logstash-6.2.4/bin/logstash -f /home/elk/logstash-6.2.4/config/logstash.conf & elif [ $Check_KIB_RET -eq 1 ]; then