Friday 12 August 2011

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 isn't found...

Possibly Related Posts

No comments:

Post a Comment