Looking at the second sub in your script (list_active), I am wondering what
you are trying to print. The script works as written (doesn't produce any
errors), but the statement:
print if $lines =~ /vty/;
doesn't print anything. Try this:
print $lines if $lines =~ /vty/;
Hope this helps.
Chris Rogers
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 14, 2001 2:43 PM
To: [EMAIL PROTECTED]
Subject: Very simple newbie problem
Thank goodness for this kind of list.
I'm very new and am experiencing some mass confusion of how things are
done. I'm trying to write a simple script to interface with a router
using Expect. This part works great, in the fact that it can log into the
router and log to a file.
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:
#!/usr/bin/perl -w
#
# This script is a test script to show what sites have active PPP sessions
#use CGI;
use Expect;
use IO::Handle;
use strict;
my $count = 0;
my $logfile = "active-connections.txt";
my $command;
my $lines;
check_active();
list_active();
sub check_active {
system("rm -f $logfile");
$command = Expect->spawn("telnet ip.add.re.ssB") or die "Can not open
telnet session to router: $!";
$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: $!";
while ($lines = <MYFILE>) {
print if $lines =~ /vty/;
}
}
What's so difficult about this?
- Scott
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]