View Single Post
  #1  
Old 12-16-2017, 11:15 PM
MADperl MADperl is offline
Registered User
 
Join Date: Dec 2017
Posts: 2
SecureCRT, screen display only 'pattern' matches?

I can use Perl to spawn a router session, select only the pattern matched lines I want to display on my terminal.

Is it possible to have that same control when using my BUTTON assigned scripts.

Directly below, is an example of a BUTTON assigned script that will issue a command to the router, then display all the lines received.

At the end of this post is an example Perl Script that will only show me the pattern matched lines I am interested in. Since I can't get that to work in SecureCRT, that Perl example is reading a log file.

Can secureCRT moderate the output to the screen?

=====================================================
SecureCRT: BUTTON assigned script
=====================================================
# $language = "PerlScript"
# $interface = "1.0"

$true = 1;
$false = 0;

$vlan = $crt->Dialog->Prompt("Enter your VLAN ID: ", "vlanid", "", $true);

$crt->Screen->{'Synchronous'} = $true;
$crt->Screen->Send("show router interface to-7705-$vlan detail\015");
$crt->Screen->Send("q");
=====================================================
=====================================================
Perl Script: Only displays lines that match a PATTERN
=====================================================
my $filename = 'C:\tmp\LogFile.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
or die "Could not open file '$filename' $!";
while (my $row = <$fh>) {
chomp $row;
my $string = $row;

if (defined($string) && ($string =~ m/# show router interface/)) {
print "$row\n"; }
elsif (defined($string) && ($string =~ m/Admin State :/)) {
print "$row\n"; }
elsif (defined($string) && ($string =~ m/Description :/)) {
print "$row\n"; }
elsif (defined($string) && ($string =~ m/Port Id :/)) {
print "$row\n"; }
elsif (defined($string) && ($string =~ m/MAC Address :/)) {
print "$row\n"; }
}
close $fh;
=====================================================
***** O U T P U T *****

*A:AAABBB00# show router interface "to-7705-2300" detail
Admin State: Up Oper (v4/v6) : Up/Down
Description: XX12345X
Port Id : 1/2/15:2300
MAC Address: a4:7b:2c:05:c9:b3 Mac Accounting : Disabled
=====================================================
Reply With Quote