Thursday, September 14, 2017

Script to check if process is running

Script to check if process is running


This is a skeleton of a watchdog script to check if a process is running:

#!/bin/bash
PROCESS="java"
log_found=`ps faux|grep -v grep|grep $PROCESS|grep -v $0|awk {print $2}`
if [ "$log_found" == "" ]; then
    echo "No process found"
else
    echo "Processes found:"
    for PID in $log_found; do
        echo $PID
    done
fi

You must change the PROCESS variable to your process name and add actions for when the process is or isnt found...

download file now

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.