#!/usr/bin/env bash set +u set -e # set -x base_dir=$( cd "$(dirname "$0")" pwd ) cd $base_dir # ./auto_del_log.sh function log_warn() { local date=$(date "+%Y-%m-%d-%H:%M:%S") local para=$1 echo "[WARN] $date $1" | tee -a "../log/run_log" } function log_info() { local date=$(date "+%Y-%m-%d-%H:%M:%S") local para=$1 echo "[INFO] $date $1" | tee -a "../log/run_log" } function log_err() { local date=$(date "+%Y-%m-%d-%H:%M:%S") local para=$1 echo "[ERROR] $date $1" | tee -a "../log/run_log" } log_path="./logs/alert/" if ps -a | grep "PrometheusAlert" | grep -v grep > /dev/null; then log_info "PrometheusAlert已在运行" elif [[ ! -f "./lib/PrometheusAlert" ]]; then log_info "no PrometheusAlert found, skip" else if [[ ! -d $log_path ]]; then mkdir -p "$log_path" fi log_file="alert_$(date "+%Y-%m-%d-%H:%M:%S").log" ./lib/PrometheusAlert &>> "${log_path}${log_file}" & sleep 1s if grep -E 'cannot|not defined' "${log_path}${log_file}" >> /dev/null; then log_err "PrometheusAlert启动遇到问题,请检查${log_file}" else log_info "PrometheusAlert启动成功!" fi fi