homepage Welcome to WebmasterWorld Guest from 54.145.252.85
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?
cschults

5+ Year Member



 
Msg#: 3531550 posted 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.

Thanks,

Chris

 

cschults

5+ Year Member



 
Msg#: 3531550 posted 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.

lammert

WebmasterWorld Senior Member lammert us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3531550 posted 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.

cschults

5+ Year Member



 
Msg#: 3531550 posted 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):

#!/bin/bash

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

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