------------------------------------------------
On Thu, 04 Sep 2003 14:23:44 -0400, zentara <[EMAIL PROTECTED]> wrote:

> On Wed, 3 Sep 2003 12:54:07 +0800, [EMAIL PROTECTED] (Jaws) wrote:
> 
> >Hi all,
> >
> >I am currently using Net::SSH::Perl module to login in my remote machine.
> >Below is my code:
> >
> >==================================
> >#!/usr/bin/perl
> >
> >use Net::SSH::Perl;
> >
> >$user="jaws";
> >$pass="password";
> >$host="111.222.333.444";
> >
> >my $ssh = Net::SSH::Perl->new($host,"'1,2'");
> >$ssh->login($user, $pass);
> >$ssh->cmd("my_command");
> >==================================
> >
> >the output of the last line requires me to input username and password. How
> >can do it using this module? I've tried to search in the manual of the
> >package but i didn't find one to answer my question and even in the web so i
> >decided to ask help from you.
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Net::SSH::Perl;
> 
> my $user = "zz";
> my $password = "ztest";
> my @hosts = qw(localhost zentara.zentara.net);
> 
> foreach my $host (@hosts){
> my $cmd = "/usr/bin/uptime";
> my $ssh = Net::SSH::Perl->new( $host, port => 22 ,debug => 1);
> $ssh->login($user,$password);
> 
> my($out) = $ssh->cmd($cmd);
> my ($time,$uptime) = (split /\s+/,$out)[1,3];
> chop $uptime;
> print "$out\n";
> print "$host has been up $uptime\n";
> }

Not sure that got to the OPs question unless you have a really weird uptime command 
that expects input. To me the best option is to put a script out on the remote host 
that handles the local inputs/outputs and then switch your 'cmd' call to call that 
script rather than the program directly.

If that is not possible and the command is expecting its input on STDIN and you don't 
need to worry about what the prompt was then you should check the docs again, in 
particular:

"($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])

If $stdin is provided, it's supplied to the remote command $cmd on standard input."

If you really need to work with an interactive interface you will probably have to 
massage the underlying socket/buffer/packets, etc. or you might be able to do 
something with the 'shell' method attached to some local filehandles that handle the 
interactive component for you, but yikes.

Though I don't usually suggest it you might consider the 'Expect' module and calling 
'ssh' on the command line.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to