LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 02:16 PM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Rep: Reputation: 3
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, 12:22 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
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, 06:02 AM   #3
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Original Poster
Rep: Reputation: 3
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, 06:32 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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, 07:23 AM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
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



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 04:46 PM
[SOLVED] problem with 6.9glibc make -k check 2>&1 | tee glibc-check-log bhismnarayan Linux From Scratch 3 10-01-2010 08:51 AM
problem with 6.9glibc make -k check 2>&1 | tee glibc-check-log bhismnarayan Linux From Scratch 1 09-30-2010 03:04 PM
[SOLVED] can someone check out my log? v00d00 ch1ld Slackware 11 05-17-2010 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:17 PM.

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
Open Source Consulting | Domain Registration