On 2006-08-18, clodoaldo.pi
...@gmail.com <clodoaldo.pi
...@gmail.com> wrote:
> I need to have a background ssh tunnel.
> It is setup like this:
> $ ssh -n -N -C -o "StrictHostKeyChecking no" -L 5433:localhost:5432
> 1.2.3.4 &
> It needs to eventually be killed and restarted with another server IP.
> What I'm doing is sending it a SIGTERM and it works but leaves a
> defunct process. This is not too big a deal but I want it clean.
So whatever's spawning ssh isn't catching the SIGCHLD when it exits and
wait()ing for the exit status?
> I have read from the man that a ~ followed by a . from stdin closes the
> connection, but the manual also states that the -n option must be used
> when ssh is to run in the background.
> What is the best approach?
If you're using a relatively recent OpenSSH then you can also use the
ControlPath socket to send an "exit command", eg:
$ ssh -MS /tmp/sock -L [forwardspec] yourserver
then you can use this to close the connection:
$ ssh -S /tmp/sock -O exit yourserver
The "-O exit" option first appeared in OpenSSH 4.2. You can put the
controlpath bits into ~/.ssh/config or ssh_config.
As Richard said, you probably want to use "-f" too.
--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.