re: ssh::command

--94eb2c05b26225962b05650faf23
Content-Type: text/plain; charset="UTF-8"

Hi all,
    I am using SSH::Command module to do ssh stuff but it does not return
full reply from server. Any clue? It just returns part of it. Is it
timeout? or what?
    Thanks.

-- 
--
Lancelot Mak

--94eb2c05b26225962b05650faf23
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi all,<div>=C2=A0 =C2=A0 I am using SSH::Command module t=
o do ssh stuff but it does not return full reply from server. Any clue? It =
just returns part of it. Is it timeout? or what?</div><div>=C2=A0 =C2=A0 Th=
anks.<br clear=3D"all"><div><br></div>-- <br><div class=3D"gmail_signature"=
 data-smartmail=3D"gmail_signature"><div dir=3D"ltr">--<br>Lancelot Mak<br>=
</div></div>
</div></div>

--94eb2c05b26225962b05650faf23--
0
lancelot
2/13/2018 3:35:00 AM
perl.beginners 29312 articles. 3 followers. Follow

9 Replies
131 Views

Similar Articles

[PageSpeed] 49

--001a113d0338404b8d056513e4ee
Content-Type: text/plain; charset="UTF-8"

Can you simplify your code to a short program that had the issue and post
it? Often the act of shortening the program reveals the problem on its own.

On Mon, Feb 12, 2018, 22:37 Lancelot Mak <lancelot.mak@gmail.com> wrote:

> Hi all,
>     I am using SSH::Command module to do ssh stuff but it does not return
> full reply from server. Any clue? It just returns part of it. Is it
> timeout? or what?
>     Thanks.
>
>
> --
> --
> Lancelot Mak
>

--001a113d0338404b8d056513e4ee
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">Can you simplify your code to a short program that had the i=
ssue and post it? Often the act of shortening the program reveals the probl=
em on its own.</p>
<br><div class=3D"gmail_quote"><div dir=3D"ltr">On Mon, Feb 12, 2018, 22:37=
 Lancelot Mak &lt;<a href=3D"mailto:lancelot.mak@gmail.com">lancelot.mak@gm=
ail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr">Hi all,<div>=C2=A0 =C2=A0 I am using SSH::Command module to do ssh stu=
ff but it does not return full reply from server. Any clue? It just returns=
 part of it. Is it timeout? or what?</div><div>=C2=A0 =C2=A0 Thanks.</div><=
/div><div dir=3D"ltr"><div><br clear=3D"all"><div><br></div>-- <br><div cla=
ss=3D"m_-3299227833607705799gmail_signature" data-smartmail=3D"gmail_signat=
ure"><div dir=3D"ltr">--<br>Lancelot Mak<br></div></div>
</div></div></blockquote></div>

--001a113d0338404b8d056513e4ee--
0
chas
2/13/2018 8:36:21 AM
--001a1144d6848a212f0565147d78
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

#!/usr/bin/perl -W

use SSH::Command;

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

$cmdlog =3D ssh_execute(
host =3D> $cmdhost,
username =3D> $user,
password =3D> $p,
command =3D> "$ARGV[1]",
);


print $cmdlog;

print "\n";


On 13 February 2018 at 16:36, Chas. Owens <chas.owens@gmail.com> wrote:

> Can you simplify your code to a short program that had the issue and post
> it? Often the act of shortening the program reveals the problem on its ow=
n.
>
> On Mon, Feb 12, 2018, 22:37 Lancelot Mak <lancelot.mak@gmail.com> wrote:
>
>> Hi all,
>>     I am using SSH::Command module to do ssh stuff but it does not retur=
n
>> full reply from server. Any clue? It just returns part of it. Is it
>> timeout? or what?
>>     Thanks.
>>
>>
>> --
>> --
>> Lancelot Mak
>>
>


--=20
Lancelot Mak
----------------------------------------------------------------
http://facebook.com/honey.mak
Used to compete
Lord to complete
=E5=BE=9E=E5=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD
=E5=A6=82=E4=BB=8A=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B
Amen

--001a1144d6848a212f0565147d78
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>#!/usr/bin/perl -W</div><div><br></div><div>use SSH::=
Command;</div><div><br></div><div><span style=3D"white-space:pre">	</span>$=
cmdln =3D `grep $ARGV[0] list.txt`;</div><div><span style=3D"white-space:pr=
e">	</span>chomp($cmdln);</div><div><span style=3D"white-space:pre">	</span=
>($cmdhost,$user,$pass) =3D split(&#39;:&#39;,$cmdln);</div><div><span styl=
e=3D"white-space:pre">	</span>$p =3D `echo $pass|base64 -d`;</div><div><spa=
n style=3D"white-space:pre">	</span>chomp($p);</div><div><br></div><div><sp=
an style=3D"white-space:pre">	</span>$cmdlog =3D ssh_execute(<br></div><div=
><span style=3D"white-space:pre">		</span>host =3D&gt; $cmdhost,</div><div>=
<span style=3D"white-space:pre">		</span>username =3D&gt; $user,</div><div>=
<span style=3D"white-space:pre">		</span>password =3D&gt; $p,</div><div><sp=
an style=3D"white-space:pre">		</span>command =3D&gt; &quot;$ARGV[1]&quot;,=
</div><div><span style=3D"white-space:pre">	</span>);</div><div><br></div><=
div><br></div><div><span style=3D"white-space:pre">	</span>print $cmdlog;</=
div><div><br></div><div><span style=3D"white-space:pre">	</span>print &quot=
;\n&quot;;</div><div><br></div><div class=3D"gmail_extra"><br><div class=3D=
"gmail_quote">On 13 February 2018 at 16:36, Chas. Owens <span dir=3D"ltr">&=
lt;<a href=3D"mailto:chas.owens@gmail.com" target=3D"_blank">chas.owens@gma=
il.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir=3D"lt=
r">Can you simplify your code to a short program that had the issue and pos=
t it? Often the act of shortening the program reveals the problem on its ow=
n.</p><div class=3D"HOEnZb"><div class=3D"h5">
<br><div class=3D"gmail_quote"><div dir=3D"ltr">On Mon, Feb 12, 2018, 22:37=
 Lancelot Mak &lt;<a href=3D"mailto:lancelot.mak@gmail.com" target=3D"_blan=
k">lancelot.mak@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr">Hi all,<div>=C2=A0 =C2=A0 I am using SSH::Command mo=
dule to do ssh stuff but it does not return full reply from server. Any clu=
e? It just returns part of it. Is it timeout? or what?</div><div>=C2=A0 =C2=
=A0 Thanks.</div></div><div dir=3D"ltr"><div><br clear=3D"all"><div><br></d=
iv>-- <br><div class=3D"m_775593518237385052m_-3299227833607705799gmail_sig=
nature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr">--<br>Lancelot =
Mak<br></div></div>
</div></div></blockquote></div>
</div></div></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>=
<div class=3D"gmail_signature" data-smartmail=3D"gmail_signature">Lancelot =
Mak<br>----------------------------------------------------------------<br>=
<a href=3D"http://facebook.com/honey.mak" target=3D"_blank">http://facebook=
..com/honey.mak</a><br>Used to compete<br>Lord to complete<br>=E5=BE=9E=E5=
=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD<br>=E5=A6=82=E4=BB=8A=
=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B<br>Amen<br></div>
</div></div>

--001a1144d6848a212f0565147d78--
0
lancelot
2/13/2018 9:19:03 AM
Hi Lancelot,

some comments on your code:

On Tue, 13 Feb 2018 17:19:03 +0800
Lancelot Mak <lancelot.mak@computer.org> wrote:

> #!/usr/bin/perl -W
>=20

1. don't use -w - http://perl-begin.org/tutorials/bad-elements/#the-dash-w-=
flag

2. use strict and warnings instead.

> use SSH::Command;
>=20
> $cmdln =3D `grep $ARGV[0] list.txt`;
> chomp($cmdln);

use file i/o or IO-All or Path-Tiny instead of ``:
http://perl-begin.org/tutorials/bad-elements/#calling-the-shell-too-much

> ($cmdhost,$user,$pass) =3D split(':',$cmdln);
> $p =3D `echo $pass|base64 -d`;
> chomp($p);
>=20

use https://metacpan.org/release/MIME-Base64 instead and avoid people snoop=
ing
on ps.
> $cmdlog =3D ssh_execute(
> host =3D> $cmdhost,
> username =3D> $user,
> password =3D> $p,
> command =3D> "$ARGV[1]",
> );
>=20

See http://perl-begin.org/tutorials/bad-elements/#vars_in_quotes .

>=20
> print $cmdlog;
>=20
> print "\n";
>=20
>=20
> On 13 February 2018 at 16:36, Chas. Owens <chas.owens@gmail.com> wrote:
>=20
> > Can you simplify your code to a short program that had the issue and po=
st
> > it? Often the act of shortening the program reveals the problem on its =
own.
> >
> > On Mon, Feb 12, 2018, 22:37 Lancelot Mak <lancelot.mak@gmail.com> wrote:
> > =20
> >> Hi all,
> >>     I am using SSH::Command module to do ssh stuff but it does not ret=
urn
> >> full reply from server. Any clue? It just returns part of it. Is it
> >> timeout? or what?
> >>     Thanks.
> >>
> >>
> >> --
> >> --
> >> Lancelot Mak
> >> =20
> > =20
>=20
>=20



--=20
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
http://is.gd/htwEXQ - Integrating GNU Guile into GNU coreutils

Give me ASCII or give me dea=C3=BE!
    =E2=80=94 http://www.shlomifish.org/humour.html

Please reply to list if it's a mailing list post - http://shlom.in/reply .
0
shlomif
2/13/2018 12:09:09 PM
--f4f5e808d7901f2d23056519c929
Content-Type: text/plain; charset="UTF-8"

On Tue, Feb 13, 2018 at 1:19 AM Lancelot Mak <lancelot.mak@computer.org>
wrote:

> #!/usr/bin/perl -W
>
> use SSH::Command;
>
> $cmdln = `grep $ARGV[0] list.txt`;
> chomp($cmdln);
> ($cmdhost,$user,$pass) = split(':',$cmdln);
> $p = `echo $pass|base64 -d`;
> chomp($p);
>
> $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->exec($command);
    $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();

    $chan->exec($command);

    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.

--f4f5e808d7901f2d23056519c929
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Feb 13=
, 2018 at 1:19 AM Lancelot Mak &lt;<a href=3D"mailto:lancelot.mak@computer.=
org" target=3D"_blank">lancelot.mak@computer.org</a>&gt; wrote:<br></div></=
div><div dir=3D"ltr"><div class=3D"gmail_quote"><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr"><div>#!/usr/bin/perl -W</div><div><br></div><div>use S=
SH::Command;</div><div><br></div><div><span style=3D"white-space:pre-wrap">=
	</span>$cmdln =3D `grep $ARGV[0] list.txt`;</div><div><span style=3D"white=
-space:pre-wrap">	</span>chomp($cmdln);</div><div><span style=3D"white-spac=
e:pre-wrap">	</span>($cmdhost,$user,$pass) =3D split(&#39;:&#39;,$cmdln);</=
div><div><span style=3D"white-space:pre-wrap">	</span>$p =3D `echo $pass|ba=
se64 -d`;</div><div><span style=3D"white-space:pre-wrap">	</span>chomp($p);=
</div><div><br></div><div><span style=3D"white-space:pre-wrap">	</span>$cmd=
log =3D ssh_execute(<br></div><div><span style=3D"white-space:pre-wrap">		<=
/span>host =3D&gt; $cmdhost,</div><div><span style=3D"white-space:pre-wrap"=
>		</span>username =3D&gt; $user,</div></div></blockquote></div></div><div =
dir=3D"ltr"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr"><div><span style=3D"white-space:pre-wrap">		</span>password =3D=
&gt; $p,, i</div></div></blockquote></div></div><div dir=3D"ltr"><div class=
=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><span=
 style=3D"white-space:pre-wrap">		</span>command =3D&gt; &quot;$ARGV[1]&quo=
t;,</div><div><span style=3D"white-space:pre-wrap">	</span>);</div><div><br=
></div><div><br></div><div><span style=3D"white-space:pre-wrap">	</span>pri=
nt $cmdlog;</div><div><br></div><div><span style=3D"white-space:pre-wrap">	=
</span>print &quot;\n&quot;;</div></div></blockquote></div></div><div dir=
=3D"ltr"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"></div></blockquote><div><br></div><div>Testing on a Mac OS machine=
, the I found it consistently prints out 8192 characters.=C2=A0 This should=
 be immediately recognizable as a magic number (8k or 2**13).=C2=A0 This te=
lls me that SSH::Command (or the underlying libssh2 library) has an 8k buff=
er and once it is full, it no longer returns any data.=C2=A0 Looking at the=
 code for SSH::Command, I see the following function:</div><div><br></div><=
div><div># Execute command and get answer as text</div><div>sub execute_com=
mand_and_get_answer {</div><div>=C2=A0 =C2=A0 my ($ssh2, $command) =3D @_;<=
/div><div>=C2=A0</div><div>=C2=A0 =C2=A0 my $chan =3D $ssh2-&gt;channel();<=
/div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 $chan-=
&gt;exec($command);</div><div>=C2=A0 =C2=A0 $chan-&gt;read(my $result, 1024=
00);</div><div>=C2=A0 =C2=A0 chomp $result; # remove \n on string tail</div=
><div>=C2=A0</div><div>=C2=A0 =C2=A0 return $result;</div><div>}</div></div=
><div><br></div><div>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 i=
s likely the problem.=C2=A0 Changing the function to read until an end of f=
ile is detected:</div><div><br></div><div><div>sub execute_command_and_get_=
answer {</div><div>=C2=A0 =C2=A0 my ($ssh2, $command) =3D @_;</div><div><br=
></div><div>=C2=A0 =C2=A0 my $chan =3D $ssh2-&gt;channel();</div><div><br><=
/div><div>=C2=A0 =C2=A0 $chan-&gt;exec($command);</div><div><br></div><div>=
=C2=A0 =C2=A0 my $result =3D &quot;&quot;;</div><div>=C2=A0 =C2=A0 until ($=
chan-&gt;eof) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $chan-&gt;read(my $bu=
f, 4_096);</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $result .=3D $buf;</div><d=
iv>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 chomp $result; # remove \n on st=
ring tail</div><div><br></div><div>=C2=A0 =C2=A0 return $result;</div><div>=
}</div></div><div><br></div><div>seems to fix the problem.=C2=A0 I am filli=
ng a bug against the module, but given that the last release was in 2009 an=
d the most current version is less than 1.0 (0.7), you may want to find a d=
ifferent module to use.</div><div><br></div><div><div><br></div></div></div=
></div></div>

--f4f5e808d7901f2d23056519c929--
0
chas
2/13/2018 3:38:15 PM
--001a1143c17ae40482056522ed6f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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

thanks

On 13 February 2018 at 23:38, Chas. Owens <chas.owens@gmail.com> wrote:

> On Tue, Feb 13, 2018 at 1:19 AM Lancelot Mak <lancelot.mak@computer.org>
> wrote:
>
>> #!/usr/bin/perl -W
>>
>> use SSH::Command;
>>
>> $cmdln =3D `grep $ARGV[0] list.txt`;
>> chomp($cmdln);
>> ($cmdhost,$user,$pass) =3D split(':',$cmdln);
>> $p =3D `echo $pass|base64 -d`;
>> chomp($p);
>>
>> $cmdlog =3D ssh_execute(
>> host =3D> $cmdhost,
>> username =3D> $user,
>>
> password =3D> $p,, i
>>
> command =3D> "$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 (8=
k
> 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) =3D @_;
>
>     my $chan =3D $ssh2->channel();
>
>     $chan->exec($command);
>     $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) =3D @_;
>
>     my $chan =3D $ssh2->channel();
>
>     $chan->exec($command);
>
>     my $result =3D "";
>     until ($chan->eof) {
>         $chan->read(my $buf, 4_096);
>         $result .=3D $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.
>
>
>


--=20
Lancelot Mak
----------------------------------------------------------------
http://facebook.com/honey.mak
Used to compete
Lord to complete
=E5=BE=9E=E5=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD
=E5=A6=82=E4=BB=8A=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B
Amen

--001a1143c17ae40482056522ed6f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">do u have any recommendation on module to use? what i want=
ed is to login ssh using username,password but in script<div>no key, no non=
-interactive</div><div><br></div><div>thanks</div></div><div class=3D"gmail=
_extra"><br><div class=3D"gmail_quote">On 13 February 2018 at 23:38, Chas. =
Owens <span dir=3D"ltr">&lt;<a href=3D"mailto:chas.owens@gmail.com" target=
=3D"_blank">chas.owens@gmail.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr"><span class=3D""><div class=3D"gmail_quote">=
<div dir=3D"ltr">On Tue, Feb 13, 2018 at 1:19 AM Lancelot Mak &lt;<a href=
=3D"mailto:lancelot.mak@computer.org" target=3D"_blank">lancelot.mak@comput=
er.org</a>&gt; wrote:<br></div></div><div dir=3D"ltr"><div class=3D"gmail_q=
uote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>#!/usr/bin/perl =
-W</div><div><br></div><div>use SSH::Command;</div><div><br></div><div><spa=
n style=3D"white-space:pre-wrap">	</span>$cmdln =3D `grep $ARGV[0] list.txt=
`;</div><div><span style=3D"white-space:pre-wrap">	</span>chomp($cmdln);</d=
iv><div><span style=3D"white-space:pre-wrap">	</span>($cmdhost,$user,$pass)=
 =3D split(&#39;:&#39;,$cmdln);</div><div><span style=3D"white-space:pre-wr=
ap">	</span>$p =3D `echo $pass|base64 -d`;</div><div><span style=3D"white-s=
pace:pre-wrap">	</span>chomp($p);</div><div><br></div><div><span style=3D"w=
hite-space:pre-wrap">	</span>$cmdlog =3D ssh_execute(<br></div><div><span s=
tyle=3D"white-space:pre-wrap">		</span>host =3D&gt; $cmdhost,</div><div><sp=
an style=3D"white-space:pre-wrap">		</span>username =3D&gt; $user,</div></d=
iv></blockquote></div></div></span><div dir=3D"ltr"><div class=3D"gmail_quo=
te"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><span style=3D"whi=
te-space:pre-wrap">		</span>password =3D&gt; $p,, i</div></div></blockquote=
></div></div><span class=3D""><div dir=3D"ltr"><div class=3D"gmail_quote"><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
 #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><span style=3D"white-sp=
ace:pre-wrap">		</span>command =3D&gt; &quot;$ARGV[1]&quot;,</div><div><spa=
n style=3D"white-space:pre-wrap">	</span>);</div><div><br></div><div><br></=
div><div><span style=3D"white-space:pre-wrap">	</span>print $cmdlog;</div><=
div><br></div><div><span style=3D"white-space:pre-wrap">	</span>print &quot=
;\n&quot;;</div></div></blockquote></div></div></span><div dir=3D"ltr"><div=
 class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"></di=
v></blockquote><div><br></div><div>Testing on a Mac OS machine, the I found=
 it consistently prints out 8192 characters.=C2=A0 This should be immediate=
ly recognizable as a magic number (8k or 2**13).=C2=A0 This tells me that S=
SH::Command (or the underlying libssh2 library) has an 8k buffer and once i=
t is full, it no longer returns any data.=C2=A0 Looking at the code for SSH=
::Command, I see the following function:</div><div><br></div><div><div># Ex=
ecute command and get answer as text</div><div>sub execute_command_and_get_=
answer {</div><div>=C2=A0 =C2=A0 my ($ssh2, $command) =3D @_;</div><div>=C2=
=A0</div><div>=C2=A0 =C2=A0 my $chan =3D $ssh2-&gt;channel();</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 $chan-&gt;exec($com=
mand);</div><div>=C2=A0 =C2=A0 $chan-&gt;read(my $result, 102400);</div><di=
v>=C2=A0 =C2=A0 chomp $result; # remove \n on string tail</div><div>=C2=A0<=
/div><div>=C2=A0 =C2=A0 return $result;</div><div>}</div></div><div><br></d=
iv><div>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.=C2=A0 Changing the function to read until an end of file is detect=
ed:</div><div><br></div><div><div>sub execute_command_and_get_answer {</div=
><div>=C2=A0 =C2=A0 my ($ssh2, $command) =3D @_;</div><div><br></div><div>=
=C2=A0 =C2=A0 my $chan =3D $ssh2-&gt;channel();</div><div><br></div><div>=
=C2=A0 =C2=A0 $chan-&gt;exec($command);</div><div><br></div><div>=C2=A0 =C2=
=A0 my $result =3D &quot;&quot;;</div><div>=C2=A0 =C2=A0 until ($chan-&gt;e=
of) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $chan-&gt;read(my $buf, 4_096);=
</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $result .=3D $buf;</div><div>=C2=A0 =
=C2=A0 }</div><div>=C2=A0 =C2=A0 chomp $result; # remove \n on string tail<=
/div><div><br></div><div>=C2=A0 =C2=A0 return $result;</div><div>}</div></d=
iv><div><br></div><div>seems to fix the problem.=C2=A0 I am filling a bug a=
gainst 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 m=
odule to use.</div><div><br></div><div><div><br></div></div></div></div></d=
iv>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">Lancelot Mak<br>---=
-------------------------------------------------------------<br><a href=3D=
"http://facebook.com/honey.mak" target=3D"_blank">http://facebook.com/honey=
..mak</a><br>Used to compete<br>Lord to complete<br>=E5=BE=9E=E5=89=8D=E8=BC=
=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD<br>=E5=A6=82=E4=BB=8A=E4=B8=80=E5=
=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B<br>Amen<br></div>
</div>

--001a1143c17ae40482056522ed6f--
0
lancelot
2/14/2018 2:32:37 AM
--------------6BD12C0F4C0DC9955E253DF8
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Try to look at Net::SSH::Any https://metacpan.org/pod/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
>
> thanks
>
> On 13 February 2018 at 23:38, Chas. Owens <chas.owens@gmail.com 
> <mailto:chas.owens@gmail.com>> wrote:
>
>     On Tue, Feb 13, 2018 at 1:19 AM Lancelot Mak
>     <lancelot.mak@computer.org <mailto:lancelot.mak@computer.org>> wrote:
>
>         #!/usr/bin/perl -W
>
>         use SSH::Command;
>
>         $cmdln = `grep $ARGV[0] list.txt`;
>         chomp($cmdln);
>         ($cmdhost,$user,$pass) = split(':',$cmdln);
>         $p = `echo $pass|base64 -d`;
>         chomp($p);
>
>         $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->exec($command);
>         $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();
>
>         $chan->exec($command);
>
>         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
> ----------------------------------------------------------------
> http://facebook.com/honey.mak
> Used to compete
> Lord to complete
> 從前輸贏在心頭
> 如今一切在主手
> Amen

--------------6BD12C0F4C0DC9955E253DF8
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Try to look at Net::<a class="moz-txt-link-freetext" href="SSH::Any">SSH::Any</a>
      <a class="moz-txt-link-freetext" href="https://metacpan.org/pod/Net::SSH::Any">https://metacpan.org/pod/Net::SSH::Any</a></p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 2/14/18 5:32 AM, Lancelot Mak wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAB8pJeBq+3CvOWRUBNNJ4rVfcuWUktnJU5Ggd7N5N4H5z78Hqw@mail.gmail.com">
      <div dir="ltr">do u have any recommendation on module to use? what
        i wanted is to login ssh using username,password but in script
        <div>no key, no non-interactive</div>
        <div><br>
        </div>
        <div>thanks</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On 13 February 2018 at 23:38, Chas.
          Owens <span dir="ltr">&lt;<a
              href="mailto:chas.owens@gmail.com" target="_blank"
              moz-do-not-send="true">chas.owens@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr"><span class="">
                <div class="gmail_quote">
                  <div dir="ltr">On Tue, Feb 13, 2018 at 1:19 AM
                    Lancelot Mak &lt;<a
                      href="mailto:lancelot.mak@computer.org"
                      target="_blank" moz-do-not-send="true">lancelot.mak@computer.org</a>&gt;
                    wrote:<br>
                  </div>
                </div>
                <div dir="ltr">
                  <div class="gmail_quote">
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div dir="ltr">
                        <div>#!/usr/bin/perl -W</div>
                        <div><br>
                        </div>
                        <div>use <a class="moz-txt-link-freetext" href="SSH::Command">SSH::Command</a>;</div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap">	</span>$cmdln
                          = `grep $ARGV[0] list.txt`;</div>
                        <div><span style="white-space:pre-wrap">	</span>chomp($cmdln);</div>
                        <div><span style="white-space:pre-wrap">	</span>($cmdhost,$user,$pass)
                          = split(':',$cmdln);</div>
                        <div><span style="white-space:pre-wrap">	</span>$p
                          = `echo $pass|base64 -d`;</div>
                        <div><span style="white-space:pre-wrap">	</span>chomp($p);</div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap">	</span>$cmdlog
                          = ssh_execute(<br>
                        </div>
                        <div><span style="white-space:pre-wrap">		</span>host
                          =&gt; $cmdhost,</div>
                        <div><span style="white-space:pre-wrap">		</span>username
                          =&gt; $user,</div>
                      </div>
                    </blockquote>
                  </div>
                </div>
              </span>
              <div dir="ltr">
                <div class="gmail_quote">
                  <blockquote class="gmail_quote" style="margin:0 0 0
                    .8ex;border-left:1px #ccc solid;padding-left:1ex">
                    <div dir="ltr">
                      <div><span style="white-space:pre-wrap">		</span>password
                        =&gt; $p,, i</div>
                    </div>
                  </blockquote>
                </div>
              </div>
              <span class="">
                <div dir="ltr">
                  <div class="gmail_quote">
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div dir="ltr">
                        <div><span style="white-space:pre-wrap">		</span>command
                          =&gt; "$ARGV[1]",</div>
                        <div><span style="white-space:pre-wrap">	</span>);</div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap">	</span>print
                          $cmdlog;</div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap">	</span>print
                          "\n";</div>
                      </div>
                    </blockquote>
                  </div>
                </div>
              </span>
              <div dir="ltr">
                <div class="gmail_quote">
                  <div><br>
                  </div>
                  <div>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 <a class="moz-txt-link-freetext" href="SSH::Command">SSH::Command</a> (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 <a class="moz-txt-link-freetext" href="SSH::Command">SSH::Command</a>, I see the
                    following function:</div>
                  <div><br>
                  </div>
                  <div>
                    <div># Execute command and get answer as text</div>
                    <div>sub execute_command_and_get_answer {</div>
                    <div>    my ($ssh2, $command) = @_;</div>
                    <div> </div>
                    <div>    my $chan = $ssh2-&gt;channel();</div>
                    <div>         </div>
                    <div>    $chan-&gt;exec($command);</div>
                    <div>    $chan-&gt;read(my $result, 102400);</div>
                    <div>    chomp $result; # remove \n on string tail</div>
                    <div> </div>
                    <div>    return $result;</div>
                    <div>}</div>
                  </div>
                  <div><br>
                  </div>
                  <div>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:</div>
                  <div><br>
                  </div>
                  <div>
                    <div>sub execute_command_and_get_answer {</div>
                    <div>    my ($ssh2, $command) = @_;</div>
                    <div><br>
                    </div>
                    <div>    my $chan = $ssh2-&gt;channel();</div>
                    <div><br>
                    </div>
                    <div>    $chan-&gt;exec($command);</div>
                    <div><br>
                    </div>
                    <div>    my $result = "";</div>
                    <div>    until ($chan-&gt;eof) {</div>
                    <div>        $chan-&gt;read(my $buf, 4_096);</div>
                    <div>        $result .= $buf;</div>
                    <div>    }</div>
                    <div>    chomp $result; # remove \n on string tail</div>
                    <div><br>
                    </div>
                    <div>    return $result;</div>
                    <div>}</div>
                  </div>
                  <div><br>
                  </div>
                  <div>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.</div>
                  <div><br>
                  </div>
                  <div>
                    <div><br>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div class="gmail_signature" data-smartmail="gmail_signature">Lancelot
          Mak<br>
----------------------------------------------------------------<br>
          <a href="http://facebook.com/honey.mak" target="_blank"
            moz-do-not-send="true">http://facebook.com/honey.mak</a><br>
          Used to compete<br>
          Lord to complete<br>
          從前輸贏在心頭<br>
          如今一切在主手<br>
          Amen<br>
        </div>
      </div>
    </blockquote>
  </body>
</html>

--------------6BD12C0F4C0DC9955E253DF8--
0
elcamlost
2/14/2018 5:33:19 AM
--94eb2c05fc52c6bd750565275547
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

thanks for the help.
it works.

On 14 February 2018 at 13:33, =D0=98=D0=BB=D1=8C=D1=8F =D0=A0=D0=B0=D1=81=
=D1=81=D0=B0=D0=B4=D0=B8=D0=BD <elcamlost@gmail.com> wrote:

> Try to look at Net::SSH::Any https://metacpan.org/pod/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
>
> thanks
>
> On 13 February 2018 at 23:38, Chas. Owens <chas.owens@gmail.com> wrote:
>
>> On Tue, Feb 13, 2018 at 1:19 AM Lancelot Mak <lancelot.mak@computer.org>
>> wrote:
>>
>>> #!/usr/bin/perl -W
>>>
>>> use SSH::Command;
>>>
>>> $cmdln =3D `grep $ARGV[0] list.txt`;
>>> chomp($cmdln);
>>> ($cmdhost,$user,$pass) =3D split(':',$cmdln);
>>> $p =3D `echo $pass|base64 -d`;
>>> chomp($p);
>>>
>>> $cmdlog =3D ssh_execute(
>>> host =3D> $cmdhost,
>>> username =3D> $user,
>>>
>> password =3D> $p,, i
>>>
>> command =3D> "$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) =3D @_;
>>
>>     my $chan =3D $ssh2->channel();
>>
>>     $chan->exec($command);
>>     $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) =3D @_;
>>
>>     my $chan =3D $ssh2->channel();
>>
>>     $chan->exec($command);
>>
>>     my $result =3D "";
>>     until ($chan->eof) {
>>         $chan->read(my $buf, 4_096);
>>         $result .=3D $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
> ----------------------------------------------------------------
> http://facebook.com/honey.mak
> Used to compete
> Lord to complete
> =E5=BE=9E=E5=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD
> =E5=A6=82=E4=BB=8A=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B
> Amen
>
>


--=20
Lancelot Mak
----------------------------------------------------------------
http://facebook.com/honey.mak
Used to compete
Lord to complete
=E5=BE=9E=E5=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD
=E5=A6=82=E4=BB=8A=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B
Amen

--94eb2c05fc52c6bd750565275547
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">thanks for the help.<div>it works.</div></div><div class=
=3D"gmail_extra"><br><div class=3D"gmail_quote">On 14 February 2018 at 13:3=
3, =D0=98=D0=BB=D1=8C=D1=8F =D0=A0=D0=B0=D1=81=D1=81=D0=B0=D0=B4=D0=B8=D0=
=BD <span dir=3D"ltr">&lt;<a href=3D"mailto:elcamlost@gmail.com" target=3D"=
_blank">elcamlost@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex">
 =20
   =20
 =20
  <div text=3D"#000000" bgcolor=3D"#FFFFFF">
    <p>Try to look at Net::<a class=3D"m_-1880842415805965166moz-txt-link-f=
reetext">SSH::Any</a>
      <a class=3D"m_-1880842415805965166moz-txt-link-freetext" href=3D"http=
s://metacpan.org/pod/Net::SSH::Any" target=3D"_blank">https://metacpan.org/=
pod/Net::<wbr>SSH::Any</a></p><div><div class=3D"h5">
    <p><br>
    </p>
    <div class=3D"m_-1880842415805965166moz-cite-prefix">On 2/14/18 5:32 AM=
, Lancelot Mak wrote:<br>
    </div>
    <blockquote type=3D"cite">
      <div dir=3D"ltr">do u have any recommendation on module to use? what
        i wanted is to login ssh using username,password but in script
        <div>no key, no non-interactive</div>
        <div><br>
        </div>
        <div>thanks</div>
      </div>
      <div class=3D"gmail_extra"><br>
        <div class=3D"gmail_quote">On 13 February 2018 at 23:38, Chas.
          Owens <span dir=3D"ltr">&lt;<a href=3D"mailto:chas.owens@gmail.co=
m" target=3D"_blank">chas.owens@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bord=
er-left:1px #ccc solid;padding-left:1ex">
            <div dir=3D"ltr"><span>
                <div class=3D"gmail_quote">
                  <div dir=3D"ltr">On Tue, Feb 13, 2018 at 1:19 AM
                    Lancelot Mak &lt;<a href=3D"mailto:lancelot.mak@compute=
r.org" target=3D"_blank">lancelot.mak@computer.org</a>&gt;
                    wrote:<br>
                  </div>
                </div>
                <div dir=3D"ltr">
                  <div class=3D"gmail_quote">
                    <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div dir=3D"ltr">
                        <div>#!/usr/bin/perl -W</div>
                        <div><br>
                        </div>
                        <div>use <a class=3D"m_-1880842415805965166moz-txt-=
link-freetext">SSH::Command</a>;</div>
                        <div><br>
                        </div>
                        <div><span style=3D"white-space:pre-wrap">	</span>$=
cmdln
                          =3D `grep $ARGV[0] list.txt`;</div>
                        <div><span style=3D"white-space:pre-wrap">	</span>c=
homp($cmdln);</div>
                        <div><span style=3D"white-space:pre-wrap">	</span>(=
$cmdhost,$user,$pass)
                          =3D split(&#39;:&#39;,$cmdln);</div>
                        <div><span style=3D"white-space:pre-wrap">	</span>$=
p
                          =3D `echo $pass|base64 -d`;</div>
                        <div><span style=3D"white-space:pre-wrap">	</span>c=
homp($p);</div>
                        <div><br>
                        </div>
                        <div><span style=3D"white-space:pre-wrap">	</span>$=
cmdlog
                          =3D ssh_execute(<br>
                        </div>
                        <div><span style=3D"white-space:pre-wrap">		</span>=
host
                          =3D&gt; $cmdhost,</div>
                        <div><span style=3D"white-space:pre-wrap">		</span>=
username
                          =3D&gt; $user,</div>
                      </div>
                    </blockquote>
                  </div>
                </div>
              </span>
              <div dir=3D"ltr">
                <div class=3D"gmail_quote">
                  <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .=
8ex;border-left:1px #ccc solid;padding-left:1ex">
                    <div dir=3D"ltr">
                      <div><span style=3D"white-space:pre-wrap">		</span>pa=
ssword
                        =3D&gt; $p,, i</div>
                    </div>
                  </blockquote>
                </div>
              </div>
              <span>
                <div dir=3D"ltr">
                  <div class=3D"gmail_quote">
                    <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div dir=3D"ltr">
                        <div><span style=3D"white-space:pre-wrap">		</span>=
command
                          =3D&gt; &quot;$ARGV[1]&quot;,</div>
                        <div><span style=3D"white-space:pre-wrap">	</span>)=
;</div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div><span style=3D"white-space:pre-wrap">	</span>p=
rint
                          $cmdlog;</div>
                        <div><br>
                        </div>
                        <div><span style=3D"white-space:pre-wrap">	</span>p=
rint
                          &quot;\n&quot;;</div>
                      </div>
                    </blockquote>
                  </div>
                </div>
              </span>
              <div dir=3D"ltr">
                <div class=3D"gmail_quote">
                  <div><br>
                  </div>
                  <div>Testing on a Mac OS machine, the I found it
                    consistently prints out 8192 characters.=C2=A0 This
                    should be immediately recognizable as a magic number
                    (8k or 2**13).=C2=A0 This tells me that <a class=3D"m_-=
1880842415805965166moz-txt-link-freetext">SSH::Command</a> (or
                    the underlying libssh2 library) has an 8k buffer and
                    once it is full, it no longer returns any data.=C2=A0
                    Looking at the code for <a class=3D"m_-1880842415805965=
166moz-txt-link-freetext">SSH::Command</a>, I see the
                    following function:</div>
                  <div><br>
                  </div>
                  <div>
                    <div># Execute command and get answer as text</div>
                    <div>sub execute_command_and_get_answer {</div>
                    <div>=C2=A0 =C2=A0 my ($ssh2, $command) =3D @_;</div>
                    <div>=C2=A0</div>
                    <div>=C2=A0 =C2=A0 my $chan =3D $ssh2-&gt;channel();</d=
iv>
                    <div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</div>
                    <div>=C2=A0 =C2=A0 $chan-&gt;exec($command);</div>
                    <div>=C2=A0 =C2=A0 $chan-&gt;read(my $result, 102400);<=
/div>
                    <div>=C2=A0 =C2=A0 chomp $result; # remove \n on string=
 tail</div>
                    <div>=C2=A0</div>
                    <div>=C2=A0 =C2=A0 return $result;</div>
                    <div>}</div>
                  </div>
                  <div><br>
                  </div>
                  <div>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.=C2=A0
                    Changing the function to read until an end of file
                    is detected:</div>
                  <div><br>
                  </div>
                  <div>
                    <div>sub execute_command_and_get_answer {</div>
                    <div>=C2=A0 =C2=A0 my ($ssh2, $command) =3D @_;</div>
                    <div><br>
                    </div>
                    <div>=C2=A0 =C2=A0 my $chan =3D $ssh2-&gt;channel();</d=
iv>
                    <div><br>
                    </div>
                    <div>=C2=A0 =C2=A0 $chan-&gt;exec($command);</div>
                    <div><br>
                    </div>
                    <div>=C2=A0 =C2=A0 my $result =3D &quot;&quot;;</div>
                    <div>=C2=A0 =C2=A0 until ($chan-&gt;eof) {</div>
                    <div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $chan-&gt;read(my $buf=
, 4_096);</div>
                    <div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $result .=3D $buf;</di=
v>
                    <div>=C2=A0 =C2=A0 }</div>
                    <div>=C2=A0 =C2=A0 chomp $result; # remove \n on string=
 tail</div>
                    <div><br>
                    </div>
                    <div>=C2=A0 =C2=A0 return $result;</div>
                    <div>}</div>
                  </div>
                  <div><br>
                  </div>
                  <div>seems to fix the problem.=C2=A0 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.</div>
                  <div><br>
                  </div>
                  <div>
                    <div><br>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear=3D"all">
        <div><br>
        </div>
        -- <br>
        <div class=3D"m_-1880842415805965166gmail_signature" data-smartmail=
=3D"gmail_signature">Lancelot
          Mak<br>
------------------------------<wbr>------------------------------<wbr>----<=
br>
          <a href=3D"http://facebook.com/honey.mak" target=3D"_blank">http:=
//facebook.com/honey.mak</a><br>
          Used to compete<br>
          Lord to complete<br>
          =E5=BE=9E=E5=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD<b=
r>
          =E5=A6=82=E4=BB=8A=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B<b=
r>
          Amen<br>
        </div>
      </div>
    </blockquote>
  </div></div></div>

</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">Lancelot Mak<br>---=
-------------------------------------------------------------<br><a href=3D=
"http://facebook.com/honey.mak" target=3D"_blank">http://facebook.com/honey=
..mak</a><br>Used to compete<br>Lord to complete<br>=E5=BE=9E=E5=89=8D=E8=BC=
=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD<br>=E5=A6=82=E4=BB=8A=E4=B8=80=E5=
=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B<br>Amen<br></div>
</div>

--94eb2c05fc52c6bd750565275547--
0
lancelot
2/14/2018 7:48:00 AM
On 02/14/2018 08:48 AM, Lancelot Mak wrote:
> thanks for the help.
> it works.
> 
> On 14 February 2018 at 13:33, Илья Рассадин <elcamlost@gmail.com
> <mailto:elcamlost@gmail.com>> wrote:
> 
>     Try to look at Net::SSH::Any https://metacpan.org/pod/Net::SSH::Any
>     <https://metacpan.org/pod/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
>>
>>     thanks

Well, this is not an answer to your question, but because it looks like
you want to use perl with ssh, you may be interested in rex -
https://www.rexify.org

It may just work for you as a tool, but you also can see the code if
that is more important for you.
Sorry if this has nothing to do with your question.
0
amestia
2/19/2018 10:41:29 AM
--94eb2c123024b7ff5205659bf6fa
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

thx for the msg. but I 'm not looking for cfg mgmt tools.

On 19 February 2018 at 18:41, Alex Mestiashvili <amestia@rsh2.donotuse.de>
wrote:

> On 02/14/2018 08:48 AM, Lancelot Mak wrote:
> > thanks for the help.
> > it works.
> >
> > On 14 February 2018 at 13:33, =D0=98=D0=BB=D1=8C=D1=8F =D0=A0=D0=B0=D1=
=81=D1=81=D0=B0=D0=B4=D0=B8=D0=BD <elcamlost@gmail.com
> > <mailto:elcamlost@gmail.com>> wrote:
> >
> >     Try to look at Net::SSH::Any https://metacpan.org/pod/Net::SSH::Any
> >     <https://metacpan.org/pod/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
> >>
> >>     thanks
>
> Well, this is not an answer to your question, but because it looks like
> you want to use perl with ssh, you may be interested in rex -
> https://www.rexify.org
>
> It may just work for you as a tool, but you also can see the code if
> that is more important for you.
> Sorry if this has nothing to do with your question.
>



--=20
Lancelot Mak
----------------------------------------------------------------
http://facebook.com/honey.mak
Used to compete
Lord to complete
=E5=BE=9E=E5=89=8D=E8=BC=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD
=E5=A6=82=E4=BB=8A=E4=B8=80=E5=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B
Amen

--94eb2c123024b7ff5205659bf6fa
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">thx for the msg. but I &#39;m not looking for cfg mgmt too=
ls.</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 19 Fe=
bruary 2018 at 18:41, Alex Mestiashvili <span dir=3D"ltr">&lt;<a href=3D"ma=
ilto:amestia@rsh2.donotuse.de" target=3D"_blank">amestia@rsh2.donotuse.de</=
a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D"">On =
02/14/2018 08:48 AM, Lancelot Mak wrote:<br>
&gt; thanks for the help.<br>
&gt; it works.<br>
&gt;<br>
&gt; On 14 February 2018 at 13:33, =D0=98=D0=BB=D1=8C=D1=8F =D0=A0=D0=B0=D1=
=81=D1=81=D0=B0=D0=B4=D0=B8=D0=BD &lt;<a href=3D"mailto:elcamlost@gmail.com=
">elcamlost@gmail.com</a><br>
</span><span class=3D"">&gt; &lt;mailto:<a href=3D"mailto:elcamlost@gmail.c=
om">elcamlost@gmail.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0Try to look at Net::SSH::Any <a href=3D"https://met=
acpan.org/pod/Net::SSH::Any" rel=3D"noreferrer" target=3D"_blank">https://m=
etacpan.org/pod/Net::<wbr>SSH::Any</a><br>
&gt;=C2=A0 =C2=A0 =C2=A0&lt;<a href=3D"https://metacpan.org/pod/Net::SSH::A=
ny" rel=3D"noreferrer" target=3D"_blank">https://metacpan.org/pod/Net:<wbr>=
:SSH::Any</a>&gt;<br>
&gt;<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0On 2/14/18 5:32 AM, Lancelot Mak wrote:<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0do u have any recommendation on module to use? =
what i wanted is to<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0login ssh using username,password but in script=
<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0no key, no non-interactive<br>
&gt;&gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0thanks<br>
<br>
</span>Well, this is not an answer to your question, but because it looks l=
ike<br>
you want to use perl with ssh, you may be interested in rex -<br>
<a href=3D"https://www.rexify.org" rel=3D"noreferrer" target=3D"_blank">htt=
ps://www.rexify.org</a><br>
<br>
It may just work for you as a tool, but you also can see the code if<br>
that is more important for you.<br>
Sorry if this has nothing to do with your question.<br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">Lancelot Mak<br>---=
-------------------------------------------------------------<br><a href=3D=
"http://facebook.com/honey.mak" target=3D"_blank">http://facebook.com/honey=
..mak</a><br>Used to compete<br>Lord to complete<br>=E5=BE=9E=E5=89=8D=E8=BC=
=B8=E8=B4=8F=E5=9C=A8=E5=BF=83=E9=A0=AD<br>=E5=A6=82=E4=BB=8A=E4=B8=80=E5=
=88=87=E5=9C=A8=E4=B8=BB=E6=89=8B<br>Amen<br></div>
</div>

--94eb2c123024b7ff5205659bf6fa--
0
lancelot
2/20/2018 2:56:36 AM
Reply: