Bash script running python scripts
<p>I new to bash script, and found one of the code from stackoverflow. I merge it with my script, it doesn't run python. When I try to echo, it is always going to "Good". When I tried to run <code>ps -ef | grep runserver*</code> this always came out and causing the python script not running. </p>

<pre><code>root      1133  0.0  0.4  11988  2112 pts/0    S+   02:58   0:00 grep --color=auto runserver.py
</code></pre>

<p>Here is my code:-</p>

<pre><code>#!/bin/sh
SERVICE='runserver*'

if ps ax | grep -v grep | grep $SERVICE &gt; /dev/null
then
    python /var/www/html/rest/runserver.py
    python /var/www/html/rest2/runserver.py
else
    echo "Good"
fi
</code></pre>

<p>If you are more familiar with python, try this instead:</p>

<pre><code>#!/usr/bin/python

import os
import sys

process = os.popen("ps aux | grep -v grep | grep WHATEVER").read().splitlines()

if len(process) == 2:
  print "WHATEVER is running - nothing to do"
else:
  os.system("WHATEVER &amp;")
</code></pre>

python linux bash shell