title: Bash script to check running process
body: <p>I wrote a bash-script to check if a process is running. It doesn't work since the ps command always returns exit code 1. When I run the ps command from the command-line, the $? is correctly set, but within the script it is always 1. Any idea?</p>
  
  <pre><code>#!/bin/bash
  SERVICE=$1
  
  ps -a | grep -v grep | grep $1 &gt; /dev/null
  result=$?
  echo "exit code: ${result}"
  if [ "${result}" -eq "0" ] ; then
      echo "`date`: $SERVICE service running, everything is fine"
  else
      echo "`date`: $SERVICE is not running"
  fi
  </code></pre>
  
  <p>Bash version: GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)</p>