Try to look at Net::SSH::Any

On 2/14/18 5:32 AM, Lancelot Mak wrote:
do u have any recommendation on module to use? what i wanted is to login ssh using username,password but in script
no key, no non-interactive


On 13 February 2018 at 23:38, Chas. Owens < <>> wrote:

    On Tue, Feb 13, 2018 at 1:19 AM Lancelot Mak
    < <>> wrote:

        #!/usr/bin/perl -W

        use SSH::Command;

        $cmdln = `grep $ARGV[0] list.txt`;
        ($cmdhost,$user,$pass) = split(':',$cmdln);
        $p = `echo $pass|base64 -d`;

        $cmdlog = ssh_execute(
        host => $cmdhost,
        username => $user,

        password => $p,, i

        command => "$ARGV[1]",

        print $cmdlog;

        print "\n";

    Testing on a Mac OS machine, the I found it consistently prints
    out 8192 characters.  This should be immediately recognizable as a
    magic number (8k or 2**13).  This tells me that SSH::Command (or
    the underlying libssh2 library) has an 8k buffer and once it is
    full, it no longer returns any data. Looking at the code for
    SSH::Command, I see the following function:

    # Execute command and get answer as text
    sub execute_command_and_get_answer {
        my ($ssh2, $command) = @_;
        my $chan = $ssh2->channel();
        $chan->read(my $result, 102400);
        chomp $result; # remove \n on string tail
        return $result;

    This looks like a fixed read (albeit a longer one that I expected,
    so there is probably a fixed buffer in libssh2 too), so that is
    likely the problem. Changing the function to read until an end of
    file is detected:

    sub execute_command_and_get_answer {
        my ($ssh2, $command) = @_;

        my $chan = $ssh2->channel();


        my $result = "";
        until ($chan->eof) {
            $chan->read(my $buf, 4_096);
            $result .= $buf;
        chomp $result; # remove \n on string tail

        return $result;

    seems to fix the problem.  I am filling a bug against the module,
    but given that the last release was in 2009 and the most current
    version is less than 1.0 (0.7), you may want to find a different
    module to use.

Lancelot Mak
Used to compete
Lord to complete

Reply via email to