bash script with permanent ssh connection
5,715
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 [email protected] and try:
autossh -f -N -L8888:127.0.0.1:3306 [email protected]
Related videos on Youtube
Comments
-
grandnasty over 1 year
I use a bash script which runs
/usr/bin/ssh -f -N -T -L8888:127.0.0.1:3306 [email protected]
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?
-
Admin almost 14 yearsWhy would your cron a ssh tunnel? Once it binds to the port, it will not be able to bind to it again.
-
Admin almost 14 yearsI 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..
-
-
Warner almost 14 years
-f
forks it to the background.