Thanks for the time you're helping me on this.  Allow me to clarify.

The file active-connections.txt contains this line:
  vty 0        admin              VTY           00:00:00  00:00:00

I ultimately want to modify the script to print /PPP/ stuff like:
  As88         mckinley_pm1       PPP           00:07:47  00:07:53

As of now, it doesn't print anything even if "vty" and "PPP" are in the
file.

The purpose, again, is to query a router of active PPP connections.  The
script then prints out a line like above.  Expect works for me and logs
the output to a file which is useful to me.

When I run the script it queries the router, writes to the file and prints
nothing.  This is where I'm frustrated.  Even though I know for sure there
is something in that file, nothing is matched and printed.

If I put sub list_active in it's own script by its lonesome, all is well.

- Scott


On Tue, 14 Aug 2001, Michael Fowler wrote:

 >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.

Another vestige of earlier revisions.

 >> 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.

Rookie error.  Thanks.

 >
 >
 >> $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