LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-05-2015, 03:16 PM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 138

Rep: Reputation: Disabled
Check if a tunnel is up - if not, log it.


I am using the following command to establish a reverse ssh tunnel with an ssh server

Code:
ssh root@my.hostname.here -R 5001:localhost:22
The server is rebooted every night and the tunnel is established automatically on reboot successfully every time.

What I need to do, is run a check, and if for some reason the tunnel is not established, I want to log it in a log file.

How can I reliably check if the tunnel is up or not?
Keep in mind that other ssh sessions might be active at the time, so I don't want the checking method to pick up any of those successful sessions. It has to check only the tunnel.

Thanks
 
Old 03-07-2015, 01:22 AM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,466

Rep: Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371
The script I posted here uses two checks.
1. Check if the process started by the ssh command is running.
2. Test if there is a listening process on the remote host.
 
Old 03-07-2015, 07:02 AM   #3
aristosv
Member
 
Registered: Dec 2014
Posts: 138

Original Poster
Rep: Reputation: Disabled
I'm looking for something that will check if there is an active tunnel connection.

The two checks you mention are useful, but don't actually check if there's a tunnel up and running.
 
Old 03-07-2015, 07:32 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
Quote:
Originally Posted by aristosv View Post
Code:
ssh root@my.hostname.here -R 5001:localhost:22
Do realize using the root account over any network is not a Best Practice.


Quote:
Originally Posted by aristosv View Post
How can I reliably check if the tunnel is up or not?
Use autossh instead then check its log file?
 
Old 03-07-2015, 08:23 AM   #5
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,466

Rep: Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371
Quote:
The two checks you mention are useful, but don't actually check if there's a tunnel up and running.
The second check tries running a command on the remote host, which requires an operational tunnel to complete successfully.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Logwatch configure to use SSH Tunnel into Mail server to Send Log reports mainlinex Linux - General 4 03-02-2011 05:46 PM
[SOLVED] problem with 6.9glibc make -k check 2>&1 | tee glibc-check-log bhismnarayan Linux From Scratch 3 10-01-2010 09:51 AM
problem with 6.9glibc make -k check 2>&1 | tee glibc-check-log bhismnarayan Linux From Scratch 1 09-30-2010 04:04 PM
[SOLVED] can someone check out my log? v00d00 ch1ld Slackware 11 05-17-2010 10:52 AM


All times are GMT -5. The time now is 01:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration