VanDyke Software Forums

VanDyke Software Forums (
-   Scripting (
-   -   SecureCRT, screen display only 'pattern' matches? (

MADperl 12-16-2017 11:15 PM

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");
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

ekoranyi 12-18-2017 09:28 AM

Hi MADperl,

SecureCRT will always display all the text sent by the remote system. That being said you may be able to get behavior similar to what you're looking for using SecureCRT's Keyword Highlighting feature.

Keyword Highlighting allows you to use color for aiding in your pattern-matching where you need to spot things that are "important". For example: Want the word "Error" to always appear on the screen in red? Or how about "Failed" or "down", etc? This is where keyword highlighting can help... and with support for regular expression highlighting (Windows only for the time being), words can be highlighted by specifying a pattern -- so you can color IP addresses for easy detection, as one example. Here's a pretty good discussion on it, with some screen shots from forum community member, Casey:

Keyword highlighting does not currently support highlighting multi word patterns. I've added you to feature requests for both multi word and full line highlighting. Should these options become available we'll be sure to post here.

Does this help get you the functionality you're looking for?

GJB56 12-19-2017 04:17 AM

I also would find multi word high lightning very useful

bgagnon 12-19-2017 07:49 AM

Hi GJB56,

I have added this thread to a feature request in our product enhancement database to support substring and phrase matches in keyword highlighting (regex with spaces). Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to and include "Feature Request - Forum Thread #12946" in the subject line or use this form from the support page of our website.

See this post for the latest info.

MADperl 12-19-2017 11:19 PM

I can work with that!

Highlighting a word, multi-word or the entire line will work fine for troubleshooting configurations aided by button defined scripts.

For report style queries from multiple MAD routers (i.e., gathering total LDP sessions, interfaces that are Up or Down, ... etc ...)

I guess I have 2 directions try. . .

Using SecureCRT
...Open a logfile to append query results to.
...Launch SecureCRT using saved sessions and a query script.
It might be problematic having the screen continuously scrolling on a laptop that is also multitasking with other work.

Using Perl with Net SSH
...Open a logfile
...Open a MAD_List file, w/host names for routers to be queried.
...Spawn router sessions, login and issue command
1st attempt at this Perl script, has a problem. Only 1 command seems to be issued and captured per login. Whatever I am doing wrong, I haven't figured it out yet.

What you have suggested will make it much easier to view relevant data "within SecureCRT" while troubleshooting configurations.

I am open to hear anyone's thoughts for improving the logic/methods for the report style processing of data from multiple MAD routers.

ekoranyi 12-20-2017 08:40 AM

Hi MADperl,

If you are wanting to connect to a defined list of devices and run the same set of commands on each, capturing the output to a log file, we have an example script available that does just that. Although it's not Perl it may still be of use to you.

The example script can be found here.

Does this help get you the functionality you're looking for?

Maureen 12-17-2019 06:04 PM

The ability to use spaces in keywords (including regular expressions) has been added to SecureCRT 8.7, which is currently in beta testing. It can be downloaded here:


All times are GMT -6. The time now is 06:10 AM.