Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've set up port forwarding over ssh so I can securely connect to a web console. Since the bash command is pretty long, I want to create a small script that will do the following;

  • Check if there is an open ssh connection to the server in question.
  • If it's not open, open it.
  • Open browser to the console I want to access.

This is what I have so far

#!/bin/sh

ssh -N -l my_username -i ~/.ssh/id_rsa_ssh -L <port>:<ip>:<port> <forwarding_ip> > /dev/null 2>&1 < /dev/null &

open -a Firefox http://localhost:<port>/url/to/something/secure

The ssh connection opens, but the browser can't establish a connection. Is there any way to programmatically open an ssh connection, background it, and ensure it stays open?

share|improve this question
2  
You need to work on your question accept rate! –  chx Oct 7 '12 at 23:56

1 Answer 1

up vote 2 down vote accepted

You wanted autossh.

autossh - Automatically restart SSH sessions and tunnels

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.