Script to establish SSH tunnel and then run another program that uses the tunnel
Posted
by
Rob Hills
on Ask Ubuntu
See other posts from Ask Ubuntu
or by Rob Hills
Published on 2012-08-29T21:23:23Z
Indexed on
2012/08/29
21:51 UTC
Read the original article
Hit count: 658
I am running a GUI app (Gnucash) that connects to a remote Postgres database via a secure shell session. I can use the SSH -L command to tunnel a local port and then separately run Gnucash and this works fine.
What I'd like to do is use a single shell script that sets up the tunnel and then calls Gnucash. Is that possible? If so, how do I do it? Currently, I run commands like the following in 2 separate terminal windows:
ssh -L 5433:127.0.0.1:19097 [email protected] gnucash postgres://gnucash@localhost:5433/gnucash_db
If I simply put both lines in a shell script, the first line drops me into the remote shell and the second line doesn't execute until I exit the remote shell.
TIA, Rob Hills
© Ask Ubuntu or respective owner