homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

Monitoring a SSH tunnel
How to determine if session is still active?

 11:28 pm on Dec 19, 2007 (gmt 0)

If I set up a SSH tunnel using remote port forwarding from one Linux machine to another, how can I check to see if the tunnel is still up?

I realize there are tools like RSTunnel and autossh, but I'm wondering how one goes about determining, via a script, if a session/process is still running.





 11:30 pm on Jan 15, 2008 (gmt 0)

Anyone? I'm guessing a combination of bash and cron scripts, though I'm not sure what the best way to test if a SSH tunnel is still active.


 12:08 am on Jan 16, 2008 (gmt 0)

On linux, the command netstat -nt grep yourip:22 should give you a list of currently active ssh connections. That list can be further processed in a script.


 8:58 pm on Jan 16, 2008 (gmt 0)

Thanks lammert. I realized I can do something similar with ps and grep. I've created a bash script that checks if the SSH session is still up and reconnects if not.

I have a feeling that there is more to this, but I've definitely made some progress.

Here is what I have thus far (comments/suggestions welcome):


while true
if ps aux grep [y]ourdomain
echo "SSH connection up."
echo "SSH connection down."
echo "Trying to connect ..."
ssh -N -f -R 3307:localhost:3306 user@www.yourdomain.com
sleep 60

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved