开发者

How to open ssh session and execute commands from a Perl script?

I have a Perl script running on a Windows machine. I need this script to open a ssh session to a remote Unix machine, and to be able to execute certain commands on that Unix machine and to be able to get the output returned from these commands.

These commands are generated during the run-time of the script, and there are many of them exec开发者_JAVA技巧uted at different times.

How can I do it?


Approach 1: Use CYGWIN: http://perlwin32ssh.blogspot.com/2007/07/test_4418.html

Approach 2: Use Net::SSH::W32Perl module.

This is one thread discussing how to install it: http://code.activestate.com/lists/perl-win32-users/29180/ (It seems to require downloading custom version of the module)

This thread should help with the problems arising from dependencies on math libraries needed for ssh calculations: http://www.issociate.de/board/post/494356/I%27m_trying_to_install_%27Net::SSH::Perl%27_on_a_Windows_Box..html

Caveat emptor: I never installed this, the above is just result of some analysis of google results.


#!/usr/bin/perl

system("ssh foo 'ls -l'");

Or go through the hassle of using ptmx(4) on the local side and ssh -t for remote.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜