开发者

Redirecting stdin/stdout to/from a remote host via ssh

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开发者_C百科 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜