Tag Archives: cygwin

bash script to check if a process instance is running

#!/bin/bash
if [ $# -ne 2 ]
then
echo "$0 process_name instances_count"
exit 1
fi

function count_match {
echo Count Match #Your code goes here
}

function count_mismatch {
echo Count Mismatch #Your code goes here
}

process=$1
exp_count=$2

run_count=`ps eax | grep ${process} | grep -v grep | wc -l`

if [ ${exp_count} -eq ${run_count} ]
then
count_match
else
count_mismatch
fi

Please note “grep -v grep” is not be required for cygwin, but even if you retain it, it doesn’t alter the behavior.

Advertisements