[Ssh-sftp-perl-users] Interfacing with network appliance through ssh
Brought to you by:
dbrobins
From: Matthew J. S. <vag...@ya...> - 2006-03-22 15:54:54
|
I have been going nuts trying to get this to work. Any help is appreciated. I need to automate the process of logging in to a network appliance and executing a few commands. The network appliance uses: OpenSSH 3.8.1 The system I am executing from is using: Redhat Linux Net::SSH::Perl 1.30 Perl 5.8.5 Here is the login process, step-by-step: # ssh username1@10.10.10.15 Then I get prompted for another username as expected. Welcome to Webstream Server Username: <Enter Username> Get prompted for Password: <Enter Password> This is where I am stuck. I have been working on the login process for a few days now, and I still cant pass the server the password. I can easily get to the point where it prompts for the password, but it does not work. Any help would be greatly appreciated. Here is what I have so far: #!/usr/bin/perl -w use strict; use Net::SSH::Perl; my %params; $params{"debug"} = 0; $params{"port"} = 22; $params{"protocol"} = 2; $params{"interactive"} = 0; $params{"compression"} = 0; $params{"PreferredAuthentications"} = 'password'; $params{"PubkeyAuthentication"} = 'no'; $params{"RSAAuthentication"} = 'no'; $params{"use_pty"} = 0; my $host = "10.10.10.15"; my $ruser = "username1"; my $user = 'username2'; my $pw = 'mypassword'; my $ssh = new Net::SSH::Perl($host, %params) || die "Cannot Connect to system $! $@\n"; print "Logging In\n"; $ssh->login($ruser) || die "Cannot Login $! $@\n"; $ssh->register_handler("stdout", sub { my($channel, $buffer) = @_; my $str = $buffer->bytes; print "\nSTR: $str\nEND\n\n"; if ($str =~ /Username: $/) { print "USER2\n"; $channel->send_data("$user\n$pw\n"); } elsif ($str =~ /Password/i) { print "\nPASSWORD2\n"; $channel->send_data($pw,"\n"); } }); my ($stdout, $stderr, $exit) = $ssh->cmd($user); print "\n\nSTDOUT - $stdout\n" if $stdout; print "STDERR - $stderr\n" if $stderr; print "EXIT $exit\n" if $exit; exit; ---------- The results are: Logging In STR: Welcome to Webstream Server Username: END USER2 STR: Password: Could not read password. Authenticating [username2]..... Authentication Failed. Good bye. [0x9] END PASSWORD2 EXIT 255 __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |