SuperSu has asked for the wisdom of the Perl Monks concerning the following question:

Here is the requirement:

I need to write a perl script to have the follow function:

Input: IP,Username,Password,command,protocal

Process: Login the switch (according to the IP) via SSH1 or SSH2 (according to the Protocal), then execute the given command

Output: The result from the switch.

Example:

Input:1.1.1.1,cisco,cisco,show version,SSH1

The script should be able to run in the following enviroment:

1. Redhat+Perl

2. WinXP+ActivePerl

So I tried the following:

1. Net::SSH::Perl - Too many dependency, can not insatll successfully and the same with Net::SSH::W32Perl.(Because of the net connection limit I must install mannuly)

2.Net::SSH::Expect for SSH1, Net::SSH2 for SSH2, this works good under linux but the Net::SSH::Expect can not be insatll under windows because of the dependency of IO::PTY (works in Cygwin though .....Why.....)

3.OpenSSH, I think this may work but I'll have to write some codes myself instead of using the package, but now I've even no idea how to write code to login the switch using SSH command (Although I know how to loging the switch by typing the command in the shell or cmd via interactive mode)

Any suggestion or advice would be great, thanks^_^

Replies are listed 'Best First'.
Re: Looking for suggestion...
by NetWallah (Canon) on Jul 15, 2010 at 04:38 UTC
    Not a perl solution, but this may be easier to setup, test, and be long-term supportable:

    Consider using putty with the plink and pagent tools.

    This should work with both Windows, and wine in Linux.

    Good luck with RTFM on those - a non-trivial learning curve for this operation, no matter which way you slice it.

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Re: Looking for suggestion...
by intel (Beadle) on Jul 15, 2010 at 02:58 UTC
    There are a lot of dependencies for Net::SSH::Perl, and you may need to install some of those manually outside of CPAN, but it's the right tool to solve your problem.

    Also, once you get it installed, you'll have trouble with performance if you don't have
    Math::BigInt::GMP

Re: Looking for suggestion...
by ww (Archbishop) on Jul 15, 2010 at 01:28 UTC
    Suggestion? Yes. Hire someone!

    This is NOT codeamatic, the free, code-writing service.

    Alternate:

    1. Read the site documents, especially On asking for help and How do I post a question effectively?
    2. Read the documentation for the modules you're considering
    3. Write some code to satisfy your requirements
    4. Test, think, re-write, correct...
          and, then:
    5. Come back with any remaining puzzles, the relevant code or snippet-size example of the problem, sample input and output and verbatim error message(s).

    Update: Too harsh. OP does not actually say that the "the requirement" constitutes something he believes the Monks are required to do. So, apologies to SuperSu.

    However, most of the "(a)lternate" suggestions above do apply

    As to your 3., you may find that reading the source for Net::SSH::Perl and related documents provides you with the required information.

Re: Looking for suggestion...
by aquarium (Curate) on Jul 15, 2010 at 04:31 UTC
    SuperSu if you provide an example of the kind of command executed on the switches (or is it always the same?) then perlmonks might provide other alternatives to the modules above. Most perlmonks have experience in the much wider technologies than just perl. Whilst this is a perl forum, if the problem is much better solved another way, someone will most likely point it out.
    Case in point if you're actually after some metrics from network devices, they're usually available via SNMP protocol, which is (usually) the best technology for network metrics gathering.
    we don't have ALL the answers, but we can try.
    the hardest line to type correctly is: stty erase ^H