I have multiple client computers (raspberry pi's) creating reverse SSH tunnels on an SSH server. I need to run a bash script on the client side, that generates a report of the status of the client. One of the checks in the report is the reverse tunnel status. I've tried the two methods below, to find out the status of the tunnel after a reboot, but the results are not reliable or consistent. Even though the tunnel is always up, most of the times the commands below report "NOT OK".

Can you suggest a better way of checking if the reverse SSH tunnel is up?

option 1
CODE
echo "Tunnel Status: $(ssh $user@$sshhost netstat -antep | grep -q "$tunnelport"; [ $? -eq 0 ] && echo "OK" || echo "NOT OK")"


option 2
CODE
echo "Tunnel Status: $(ssh $user@$sshhost lsof -iTCP -sTCP:LISTEN | grep sshd | grep :$tunnelport | grep -o LISTEN; [ $? -eq 1 ] && echo "NOT OK")"


client
CODE
user@Client001:~# cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"


server
CODE
user@SSH-Server:~# cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"