E-mail : support@tech2now.in

How to check application process is running or not using shells script

Linux Linux command ls pwd cp mv more grep tail

Script to check process is running or not.

Create a script using the command $vim script.sh and

Copy the below script and save it.

#!/bin/bash

#Set the process name to be checked
PROCESS_NAME=”myprocess”

#Check if the process is running
if pgrep $PROCESS_NAME > /dev/null
then
echo “$PROCESS_NAME is running.”
else
# Send an email notification
SUBJECT=”$PROCESS_NAME is not running”
EMAIL_BODY=”The $PROCESS_NAME process is not running on $(hostname). Please investigate.”
echo “$EMAIL_BODY” | mail -s “$SUBJECT” user@example.com
fi

Create a cron job for the same

crontabe -e
*/5 * * * * * /Script_path/script.sh