Wait for python script to return 0
<p>I'am  trying to write a script that is waiting for a database to be online.
The script that checks the database connection is written in python and should be excited every 5 seconds. If the script returns 0 the main script should continue.</p>

<p>I have never written in shell, so i can only guess how to get the python script into the condition of the while loop. Here is my attempt, but i have no idea how to get it right.</p>

<p>The python script is working well.</p>

<p>psqltest.py:</p>

<pre><code>#!/usr/bin/python2.4
#
import psycopg2
try:
    db = psycopg2.connect("dbname='postgis' user='postgres' host='db' password='postgres'")
except:
    exit(1)

exit(0)
</code></pre>

<p>my main shell script:</p>

<pre><code>echo waiting for database...
while  [ python /root/psqltest.py &amp;&amp; echo 0 || echo 1 ]
  do
     sleep 5
  done
</code></pre>

<p>the error message:</p>

<pre><code> 1 ]
</code></pre>

<p>Thanks for helping me out</p>