Jeff Abrahamson on 4 Mar 2004 17:11:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Weird Bash Question


On Thu, Mar 04, 2004 at 11:37:33AM -0500, Martin DiViaio wrote:
>   [29 lines, 147 words, 1019 characters]  Top characters: _teoslia
> 
> 
> 
> 
> > Why do you want to do this, though? Binding to "0" gets you an
> > unused socket which you then own, meaning there's no chance for a
> > race condition between when you get the number and start using the
> > socket.
> > 
> > What problem are you trying to solve?
> 
> I have a shell script that sets up a local ssh tunnel to another system 
> like so:
> 
> ssh -2 -x -f -C -L 3389:windows_server_at_work:3389 martin@linux_box_at_work sleep 1
> 
> I then do:
> 
> rdesktop -g 1024x768 localhost
> 
> My problem is when I need to set up a second tunnel I can't use the
> shell script and have to do the commands manually pointing the local
> side to another port. I could make guesses in my shell script but
> I'm looking for a better solution.

Check out the -N flag to SSH, it saves you the sleep 1.

Noting that (2^16 - 1) - 1024 = 64511, and that most of the
(non-privileged) ports between 1024 and 65535 are probably free, you
have a pretty good chance of having your script work most of the time
like this:

    p=`perl -we 'print 1024+int(rand(64511))'`; echo Trying port $p; \
        ssh -2 -N -x -f -C -L $p:windows_server_at_work:3389 martin@linux_box_at_work

Perl picks a random port for you, then you use your script on that
port, having echoed it at step 2.

But if your win box can accept two connections, why can't the
listening ssh process also?  I should think you should be able to run
several rdesktop commands for a single ssh tunnel.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

Attachment: signature.asc
Description: Digital signature