On Tue, Aug 14, 2001 at 02:43:29PM -0400, [EMAIL PROTECTED] wrote:
> The second part of the script looks in the file and searches for a
> particular connection type and prints the line.  If I separate the two
> functions into separate scripts things work well.  Combining them into the
> same script is driving me nuts.  Here's the example:

I need a little more elaboration on why it's driving you nuts.  What are you
getting?  What did you expect.

 
> #!/usr/bin/perl -w

-w, good.


> #
> # This script is a test script to show what sites have active PPP sessions
> #use CGI;
> use Expect;

Why are you using Expect for this.  Net::Telnet seems more appropriate.


> use IO::Handle;
> use strict;

use strict, good.

 
> my $count = 0;

I don't see this variable every used.  I'm assuming it's a vestige from an
earlier revision.


> my $logfile = "active-connections.txt";

You set this variable here, and use it in all of one place, meanwhile using
the constant, "active-connections.txt".  You should use $logfile everywhere.


> my $command;
> my $lines;

These variables should not be declared here, they should be declared in the
smallest possible scope that needs them.  See below.

 
> check_active();
> list_active();
> 
> sub check_active {
> system("rm -f $logfile");

Use unlink, perldoc -f unlink.  Also, you need to check your return value,
regardless of whether you use unlink or system.


> $command = Expect->spawn("telnet ip.add.re.ssB") or die "Can not open
> telnet session to router: $!";

Here is where you should declare $command.

    my $command = Expect->...


> 
>         $command->log_stdout(0);
>         $command->log_file("active-connections.txt");
> 
>         print $command "admin\n";
>         print $command "password\n";
>         print $command "sho caller\n";
>         print $command "exit\n";
> 
> $command->soft_close();
> #$command->hard_close();
> }
> 
> sub list_active {
>         open (MYFILE, "<active-connections.txt") || die "can not open
> file: $!";

Here is where you should declare $lines.

          my $lines;

And you probably shouldn't call it '$lines'; a plural variable name
indicates it contains more than one value, this only ever contains one line.

So, you should either rename it $line, or omit it altogether, as in:

    while (<MYFILE>) {
        print if /vty/;
    }

>         while ($lines = <MYFILE>) {
>                 print if $lines =~ /vty/;
>         }
> }


I have no idea if the above suggestions will solve your problem.  Once you
give us a better idea of what your problem is we can give you some tips on
what's wrong and how to fix it.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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

Reply via email to