I've got a small script that is going into a much larger script that is
killing me as to why it is not working....

When I try and execute it I get:

[paul@kenny backup]$ perl test2.pl
Name "Start::skip" used only once: possible typo at test2.pl line 52.
Can't call method "waitfor" on an undefined value at test2.pl line 39.

I know about the Start::skip used only once - I'm not to the point of
adding the rest of what that is going to be for, but the problem is the
"Can't call method..."

If I use $t as a globally defined variable, it works, but I need it to
be contained within the subroutines that actually do the telnetting and
logging.  This is a small part of a very large project...

Any help would be greatly appreciated.

Thanks,
Paul


#!/usr/bin/perl -w

# Program for logging into Foundry and Cisco switches/routers
#  and backing up specific information

use strict;
use Net::Telnet;
my ($ipaddr, $logfile, @command_out);

$ipaddr = "10.1.1.4";
$logfile = "testlog.log";
@command_out = ("sh ver", "sh tech");

&start;

sub start {

        package Start;
        my ($t, @output, $prompt);
        
        ## Setup new connection and login
        $t = new Net::Telnet;
        $t->open("$ipaddr");

        &login;

        ## Opens Logfile for writing
        open (OUTPUT, ">$logfile") || die "blah";

        ## Start the backup
        $prompt = '/.*[#>]$/';
        foreach (@command_out) {
                @output = $t->cmd(String => $_, Prompt => $prompt);
                print OUTPUT @output;
        };
};

sub Start::login {
        my ($passwd, $en);
        $passwd = "mypasswd";
        $en = "en";
        $Start::t->waitfor('/password/i');    ##### this is line 39
        $Start::t->print($passwd);
        $Start::t->print($en);
        $Start::t->waitfor('/password/i');
        $Start::t->print($passwd);
};

sub Telnet_in::identify {
        # Used for skip-page-display (Foundry) or length 0 (Cisco)
        package Identify;
        my ($shver, @shver);
        @shver = $Start::t->cmd(String => "sh ver", Prompt => $Start::prompt);
        if ($shver[0] =~ /Foundry/) {
                $Start::skip = "skip-page-display";
        } else {
                &cisco_skip;
        };
};

sub Start::Identify::cisco_skip {
        my (@commands, @output);
        #@commands = ("conf t", "line vty 0 4", "length 0", "end");
        @commands = ("conf t", "hostname TEST", "end");
        foreach (@commands) {
                @output = $Start::t->cmd(String => $_, Prompt => $Start::prompt);
        };
};


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

Reply via email to