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

msg:3531552 | 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

msg:3549181 | 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

msg:3549226 | 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

msg:3550078 | 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
|
|
|