Thanks Corion, It works fine on Linux platform, and not work on Windowns for SSH But everytime I issue $ssh->capture($cmd), I need to input password again. my code:

use strict; use warnings; use Net::SSH::Any qw(); my $ssh = Net::SSH::Any->new( '172.21.71.197', user => 'root', password => 'r3 +v3nue' ); my @tmp = $ssh->capture('ls -lrt'); print "@tmp \n"; print "====================\n"; @tmp = $ssh->capture('date'); foreach (@tmp) { if ( $_ =~ /(\d+:\d+:\d+)/ ) { print "Time is $1"; last; } }
Output:
root@svr1087# perl test.pl root@172.21.71.197's password: total 88 -r-xr-xr-x. 1 root root 332 Apr 22 2015 patchC3iptablesCustom.sh -r-xr-xr-x. 1 root root 508 Apr 23 2015 jre1.6.sh dr-xr-xr-x. 2 root root 4096 Nov 8 2018 Adax -rw-r--r--. 1 root root 1807 Jul 19 17:55 preinstall.log -rw-r--r--. 1 root root 6782 Jul 19 17:58 install.log.syslog -rw-r--r--. 1 root root 25057 Jul 19 18:00 install.log -rw-------. 1 root root 10302 Jul 19 18:00 anaconda-ks.cfg -rw-r--r--. 1 root root 14788 Jul 19 18:03 postinstall.log -rw-r--r-- 1 root root 4 Jul 22 14:11 hung_task_timeout_secs~ ==================== root@172.21.71.197's password: Time is 05:06:39# + + + root@svr1087#

In reply to Re^4: [Help]Build a tool/application using Perl by tctoa
in thread [Help]Build a tool/application using Perl by tctoa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.