Re: how to get the PID of an SSH tunnel

From: Darren Tucker (dtucker_at_dodgy.net.au)
Date: 03/05/04


Date: Thu, 4 Mar 2004 23:40:27 +0000 (UTC)

In article <c9d82136.0403041335.68d710cb@posting.google.com>,
Noah <noah@noah.org> wrote:
>pa@invalid.invalid (Pierre Asselin) wrote in message news:<3ne32c.e9s.ln@brick.verano.sba.ca.us>...
>> Noah <noah@noah.org> wrote:
>> > I'm creating an SSH tunnel using a command like this:
>> > ssh -C -n -L 25:example.com:25 -L 110:example.com:110 \
>> > my_name@example.com -f nothing_script.sh
>> The shell variable $! contains the pid of the most recently executed
>> background command. If you leave out the -f and background the ssh
>> yourself, the $! will have what you want. (You can also use -N
>> instead of an empty script.)
>
>The problem is that SSH does a fork/exec, so the pid is not what the shell sees
>as the SSH command it started (that is, $! doesn't work).
>The -N argument implies -f. You cannot leave off the -f and
>put it into the background youself because then you cannot
>enter the password. With -f or -N SSH will ask you for your password
>before it daemonizes itself. In other words, if you try to do this:
> ssh -C -n -L 110:example.com:110 my_name@example.com nothing_script.sh &
>Then I will see SSH ask me for a password, but there is no way to enter it.
>And, no, I am not allowed to use public key authentication :-P
>Finally, I'm forced to talk to an old SSH1 server, so -N doesn't work anyway.

There's an open enhancement request for this:
http://bugzilla.mindrot.org/show_bug.cgi?id=253

-- 
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.


Relevant Pages

  • grab output from spawned command
    ... Way im thinking of doing it is by getting the pid of a spawned ssh ... want the whole script to fail. ... existence of a remote file so im using this connection test for 2 things). ...
    (SunManagers)
  • Re: get the pid of a process with pexpect
    ... tunnel for the duration of your script. ... PID in $! ... because SSH does not provide a way to get the PID of the tunnel if you ... start the tunnel from a shell you can't use $! ...
    (comp.lang.python)
  • Re: ssh
    ... I have an ssh key stashed already for my user ID, ... I dont understand what happens when pid does not equal 0, ... res = '' ...
    (comp.lang.python)
  • Re: [regression] nf_iterate(), BUG: unable to handle kernel NULL pointer dereference
    ... CPU 0 ... Pid: 5331, comm: ssh Not tainted 2.6.26 #21613 ...
    (Linux-Kernel)
  • Re: How to catch process start
    ... > any user come to system neither via telnet, ssh,web, or the other ... > I only would like to get pid of the first process of those user. ...
    (comp.unix.programmer)

Quantcast