I'm just playing around with bash to understand it better. I've tried many different lines of code.
I'm trying to create a loop to check for process using ps aux. For this example i took sabnzbdplus and sickbeard.
I want to detect if one is running, and if not, start the program.
for PROCESS in $PROGRAMS
do ps aux | grep -c $PROCESS #> /dev/null #check output (1 or 2)
if [ $? -eq 2 ]; then
echo "Process is running ($PROCESS)"
#if [ $? -eq 1 ]; then
echo "Process is not running ($PROCESS)"
if [ "$PROCESS" == "sabnzbd*" ]; then
else if [ "$PROCESS" == "SickBeard*" ]; then
Process is not running (sabnzbd)
Process is not running (SickBeard)
I commented "> /dev/null" to check the output.
Somehow it's not working. Figure it's got something to do with [ $? -eq 2 ]