title: loop execute command while port/connection is closed to maintain SSH tumnel
body: <p>I am trying to write a script that will maintain a ssh tunnel for me in background on an android device using init.d. </p>
  
  <pre><code>#!/system/xbin/bash
  
  . /system/etc/sshd.conf
  
  while ! ping -c1 www.google.com &amp;&gt;/dev/null; do:; 
  done
  
  ssh -T -K 120 -i "$KEYFILE" -R "$REVPORT":localhost:"$PORT "$REMUSER"@"$REMSERV" -p "$REMSERVPORT" -y
  </code></pre>
  
  <p>What I need is a loop that will continuously check every X secs if there is an active connection to $REMSERV/$REMSERVPORT if it closes run the ssh line &amp; continue checking. keeping in mind I have a limited set of CLI tools at my disposal. I was looking into autossh instead but I couldn't find a compiled binary for my platform. I am wondering if netstat could help with this? I appreciate ANY feedback &amp; explanations on how code works.</p>