#!/bin/bash # 这里 grep -vE 必须有, 否则会杀死全部进程.. pids=`ps -ef | grep 'prometheus'| grep -vE '(grep|/bin/bash|bash|sh)' | tr -s ' '| cut -d ' ' -f 2` echo "进程 id" pids=(${pids// / }) echo $pids pid=${pids} for var in ${pids[@]};do echo $var done if [ $pid ] then echo "执行 ‘kill $pid’ " kill $pid fi cd /usr/prometheus nohup ./prometheus --config.file=prometheus.yml > /dev/null & echo '重启 prometheus 成功' exit 0