I use a bash script which runs

/usr/bin/ssh -f -N -T -L8888:127.0.0.1:3306 serveradmin@34.324.234.23

However, when I run the bash script, it waits.. I see the connection coming up but the script doesn't exit.. it's like it's waiting for the SSH process to finish, because when I manually kill it the bash script finishes as well.

Any ideas how to resolve this?

UPDATE: I have croned this script.. and the cron process is the one that becomes a zombie.. the actual scripts runs just fine, sorry about that, with ps -auxf I get:

root       597  0.0  0.7   2372   912 ?        Ss   Jul12   0:00 cron
root      2595  0.0  0.8   2552  1064 ?        S    02:09   0:00  \_ CRON
1001      2597  0.0  0.0      0     0 ?        Zs   02:09   0:00      \_ [sh] <defunct>
1001      2603  0.0  0.0      0     0 ?        Z    02:09   0:00      \_ [cron] <defunct>

and when I kill the ssh the defuncts disappear.. why would they become defunct?

link|improve this question
Why would your cron a ssh tunnel? Once it binds to the port, it will not be able to bind to it again. – Warner Jul 13 '10 at 14:00
I know, in the script I check if the tunnel is there already, if so do nothing.. if tunnel isn't there, bring it back up. This is to ensure the tunnel is always there.. – samuelf Jul 13 '10 at 22:54
feedback

3 Answers

It seems you're trying to reimplement bits of autossh (apt-get install autossh).

Create a RSA key pair without a passphrase, install the public key on serveradmin@34.324.234.23 and try:

autossh -f -N -L8888:127.0.0.1:3306 serveradmin@34.324.234.23
link|improve this answer
feedback

detach ssh process from your terminal

  1. Send it to background

    /usr/bin/ssh -f -N -T -L8888:127.0.0.1:3306 serveradmin@$34.324.234.23 &

  2. Nohup it

    nohup /usr/bin/ssh -f -N -T -L8888:127.0.0.1:3306 serveradmin@$34.324.234.23

link|improve this answer
1  
-f forks it to the background. – Warner Jul 12 '10 at 23:57
thanks, however please see update. – samuelf Jul 13 '10 at 0:13
feedback

Remove the $.

workstation:~$ /usr/bin/ssh -f -N -T -L8888:127.0.0.1:3306 server.host.com
DSA host key for IP address '205.205.219.5' not in list of known hosts.
workstation:~$ ps x | grep '\-f'
16170 ?        S      0:00 /usr/bin/ssh -f -N -T -L8888:127.0.0.1:3306 server.host.com

It goes straight to the background as you detail for me. I do have a keypair setup on my test server, however.

Do you already have something listening on 8888 on your local server? Do you already have an instance in the background?

link|improve this answer
thanks, however please see update. – samuelf Jul 13 '10 at 0:13
feedback

Your Answer

 
or
required, but never shown

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