#!/bin/bash# ------------------------------------------------------------# Bash script to check processes.# ------------------------------------------------------------# RETURN CODE# 0: processes are not running.# 1: one process is running. (CPU time < configured value)# 2: one process is running. (CPU time >= configured value)# 3: more than two processes are running.# ------------------------------------------------------------#PS_NAME="<process_name>"CPU_MAX=000100# Format: `HHMMSS`# Process countsCNT=`ps -ef | grep -e "$PS_NAME"| grep -v grep | wc -l`if[$CNT -eq 0];thenecho"[RET-CODE:0] processes are not running."exit 0
elif[$CNT -eq 1];then# CPU timeTM=`ps -ef | grep -e "$PS_NAME"| grep -v grep | awk '{ print $7 }'`TM=${TM:0:2}${TM:3:2}${TM:6:2}if[$TM -lt $CPU_MAX];thenecho"[RET-CODE:1] one process is running. (CPU time < configured value)"exit 1
elseecho"[RET-CODE:2] one process is running. (CPU time >= configured value)"exit 2
fielseecho"[RET-CODE:3] more than two processes are running."exit 3
fi