Nalina has asked for the wisdom of the Perl Monks concerning the following question:
When I execute this script, I got the following error#!/usr/local/bin/perl -w # Steps: # 1. login # 2. go to enable mode ('en') # 3. execute 'no pager' to disable paging # 4. execute 'sh access-list access-list-name' # 5. Get hit counts # 6. logout $|++; use strict; use Net::SSH::Perl; use Net::SSH::Perl::Constants qw( :msg ); use constant SKIP_PROMPT => 1; # pix prints login prompt twice, skip + first my $host = shift || die "Usage: $0 pix_name\n"; my $time2login = 10; my $time2run = 20; my $file = "C:\\hit_cnt.txt"; open (DAT, ">>$file") || die "can not open"; # modify these in case of prompt (hostname) changes # assuming alphanumeric characters only: # [a-zA-Z0-9] is actually \w, but some hosts have '_' or '-' in their +names my $enb_prompt = qr/(?:[a-zA-Z0-9]+#)\s*/; # alphanumeric followed b +y '#' my $reg_prompt = qr/(?:[a-zA-Z0-9]+>)\s*/; # alphanumeric followed b +y '>' my $pass_prompt = qr/Password:\s*/; my ($prompt_cnt,$save,$done) = (0,0,0); my ($ssh, @config); # login on the device eval { local $SIG{'ALRM'} = sub { die 'TimedouT' }; alarm $time2login; $ssh = Net::SSH::Perl->new($host, protocol=>1, cipher=>'DES', port= +>22); $ssh->login('USER-NAME','PASSWD'); alarm 0; }; ($@)? ( die '[',scalar localtime,'] ', ($@ =~ /TimedouT/)? "Takes too long to login on $ho +st.\n" : "Unexpected eval err: $@.\n" ) : undef; # set up handler and intercept everything that goes to STDOUT $ssh->register_handler(SSH_SMSG_STDOUT_DATA, sub { my($ssh, $packet) = @_; my $str = $packet->get_str; print DAT "$str"; if ( $save ) { # reading config if ( $str =~ /$enb_prompt$/ ) { # last line of the config + p +rompt my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('exit ' . "\n"); $packet->send; $done++; } $str =~ s/\cM//g; chomp $str; # skip echo of the command and logout sequence push @config, $str unless ( $done || $str =~ /^(\w|\s)$/ +|| $str =~ /^:/ || $str eq '' ); } else { # login part if ($str =~ /$reg_prompt$/) { # go to enable mode $prompt_cnt++; # pix prints login prompt twice +, remember return unless $prompt_cnt > SKIP_PROMPT; my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('enable' . "\n"); $packet->send; $prompt_cnt = 0; # will resuse it in enable mode + } elsif ( $str =~ /$pass_prompt$/ ) { # going into enable mode.... my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str("PASSWD\n"); $packet->send; } elsif ( $str =~ /$enb_prompt$/ && !$prompt_cnt ) { # exec first command in enable mode my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('no pager' . "\n"); $packet->send; $prompt_cnt++; } elsif ( $str =~ /$enb_prompt$/ && $prompt_cnt ) { # exec second command in enable mode, ready to rock my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('sh access-list access-list-name' . "\n"); $packet->send; $save++; } else { # Uncomment this for debug purposes # print "Useless data: $str\n"; } } }); eval { local $SIG{'ALRM'} = sub { die 'TimedouT' }; alarm $time2run; $ssh->cmd(''); # thaaaat's right, nothing at all alarm 0; }; ($@)? ( die '[',scalar localtime,'] ', ($@ =~ /TimedouT/)? "Timed out while pulling from $ +host.\n" : "Unexpected eval err: $@.\n" ) : undef;
How do I resolve it?Use of uninitialized value in concatenation (.) or string at C:/Perl/s +ite/lib/Net/SSH/Perl.pm line 111. Nalina: Reading configuration data /.ssh/config Nalina: Reading configuration data /etc/ssh_config Nalina: Connecting to 203.91.132.111, port 22. Nalina: Remote protocol version 1.5, remote software version Cisco-1.2 +5 Nalina: Net::SSH::Perl Version 1.23_01, protocol version 1.5. Use of uninitialized value in concatenation (.) or string at C:/Perl/s +ite/lib/Net/SSH/Perl/SSH1.pm line 31, <GEN0> line 1. Use of uninitialized value in concatenation (.) or string at C:/Perl/s +ite/lib/Net/SSH/Perl/SSH1.pm line 37, <GEN0> line 1. Nalina: No compat match: Cisco-1.25. [Wed Jun 23 12:37:28 2004] Unexpected eval err: Your vendor has not de +fined Fcntl macro F_SETFL, used at C:/Perl/site/lib/Net/SSH/Perl.pm l +ine 218.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SSH to a pix
by tachyon (Chancellor) on Jun 23, 2004 at 07:42 UTC | |
by PodMaster (Abbot) on Jun 23, 2004 at 08:36 UTC | |
by tachyon (Chancellor) on Jun 23, 2004 at 12:52 UTC | |
by Nalina (Monk) on Jun 24, 2004 at 06:59 UTC | |
by Nalina (Monk) on Jun 23, 2004 at 08:27 UTC | |
by tachyon (Chancellor) on Jun 23, 2004 at 10:35 UTC | |
|
Re: SSH to a pix
by tachyon (Chancellor) on Jun 23, 2004 at 12:55 UTC |