How to determine if a Unix/Linux application is running

book

Article ID: 180024

calendar_today

Updated On:

Products

Management Platform (Formerly known as Notification Server) Monitor Solution

Issue/Introduction

 

Resolution

Question
How do I determine if a Unix/Linux application is running?

Answer

Below is a shell script that will check for a process running. All you would need to modify the proc_name variable below.

If you were using this in Monitor Solution, use a command metric that leverages the command=”” below.

If you are using this via custom inventory, use a custom inventory script that dumps the entire process list then reports on any instance that includes the Weblogic command.


###################################################################################
# A simple shell script that can be used to tell if a process is running on a     #
# UNIX/Linux computer. The working directory, process name are provided on the    #
# first two lines of the script below.                                            #
###################################################################################

proc_name="WEBLOGIC_PROC_NAME"
command=`ps aux|grep $proc_name | grep -v grep | awk '{print $11}'`
if [ -z "$command" ]; then
echo "The process ($proc_name) is NOT running (failure)"
# YOU COULD INSERT CODE HERE THAT IS EXECUTED WHEN THE PROCESS IS FOUND
# NOT TO BE RUNNING.  E.G. A COMMAND LINE THAT WOULD START THE PROCESS
# AGAIN.

else
echo "The process ($proc_name) is already running (success)"
# AGAIN YOU COULD ADD ADDITIONAL CODE HERE THAT IS EXECUTED WHEN THE PROCESS
# IS FOUND TO BE RUNNING SUCCESSFULLY.
fi