title: How to write a time condition loop over a if-else
body: <p>I have a if-else condition as follows:</p>
  <pre><code>if [[ &quot;${DB_LOCK}&quot; == &quot;Done&quot; ]]; then
      echo &quot;DB image is ready, starting instances creation...&quot;
  else
      if [[ &quot;${DB_LOCK}&quot; == &quot;FAILED&quot; ]]; then
          echo &quot;Failed to read db_lock.txt&quot;
      else
          echo &quot;DB image is not yet ready, trying again later...&quot;
      fi
      exit 1
  fi
  </code></pre>
  <p>After this loop, it actually run the <code>docker image prune -a --force</code> to cleanup all unused containers. But, sometimes it stuck in the above loop and never goes to this cleanup step.</p>
  <p>Goal: give a explicit waiting period for the loop, using another loop after that period it should exit the loop with error and move to the next steps.</p>