1

I'm trying to write a perl script that redirects its stdin to a remote machine and at the same time redirects the stdout of the remote machine to its stdout:

callingProgram <--> myScript <--> sshTunnelToRemote

See this question and bdonlan's answer for the purpose of the script.

First I tried to use the open2() function from the IPC library but for reasons described here it doesn't seem to be a good approach, I didn't even get a simple grep command working.

My second idea was to use the Net::SSH::Perl or the Expect libraries but they're not available on the machine where the script is supposed to be executed and I can't install libraries there.

So my question is what could be a simple way to achieve what I want? Solutions using [ba]sh or even C++ are also possible. The targeted platform is Solaris 10.

Community
  • 1
  • 1
Deve
  • 4,528
  • 2
  • 24
  • 27
  • Explain the reason why/what makes you think you "can't install libraries there". – daxim Apr 16 '11 at 16:47
  • I have tried it. The installer tried to create files at locations where I don't have write permission and therefore failed. – Deve Apr 16 '11 at 17:09
  • Tunnels are for sockets. open2 doesn't create sockets. You want to create a socket, connect it to the tunnel, then dup that socket unto STDIN and STDOUT. – ikegami Apr 16 '11 at 17:50

2 Answers2

2

Seems like you could probably get away with nothing more than system() — don't pass the data from your stdin to ssh's stdin and from your stdout to ssh's stdout; just let ssh inherit your stdin and stdout. Unless you need to modify the data in transit somehow.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • Thanks for your answer. How would I implement this inheritance? – Deve Jun 11 '11 at 15:42
  • @Deve by doing nothing and calling `system("ssh", "remotehost", "somecommand")`. – hobbs Jun 11 '11 at 17:11
  • Hm, I don't know if I got your idea. What would `somecommand` be? It's unknown when calling the script. I think I'll install a newer version of ssh that supports the `-W` option. – Deve Jun 11 '11 at 18:12
0

cpanminus can do this for you

Running:

cd ~/bin
curl -LO http://xrl.us/cpanm
chmod +x cpanm

Now you can try your problem using the right tools (e.g. Net::SSH::Perl).

The power of perl is cpan, and cpanminus gives you the ability to install whatever you need even if you don't have permission to install to the system-wide libraries.

Read the module documentation for the full details.

unpythonic
  • 4,020
  • 19
  • 20