Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> reliably check if a reverse ssh tunnel is up
aristosv
post Apr 4 2016, 12:47 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 8
Joined: 27-March 15
Member No.: 18,860



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/"
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 18th October 2017 - 06:21 AM