Sponsored Content
Top Forums Shell Programming and Scripting Perl Regular Expression Word Search Post 302362924 by xmaverick on Sunday 18th of October 2009 07:51:31 PM
Old 10-18-2009
Perl Regular Expression Word Search

I'm trying to have my perl script telnet into the network device execute a command then dump the output of the command into a variable. The script then greps for the word "STANDBY". I can't seem to get the script to print out the output because it seems that the script can't find the word "STANDBY". I believe this is because i'm not using good regular expression.



Code:
#!/usr/bin/perl -w 
  
use strict; 
use warnings; 
use Net::Telnet; 
  
my $ip = $ARGV[0]; 
my $pass = "mgcusr"; 
my $pass2 = "S3attl3"; 
my $t=new Net::Telnet(Errmode=>'return',Input_Log => "/tmp/input.log",Timeout=>30); 
  
  
$t->open($ip); 
 if($t->errmsg) { my $err=$t->errmsg; return $err; } 
 my ($prompt) = $t->waitfor('/login: $/'); 
    if($t->errmsg) { my $err=$t->errmsg; return $err; } 
    $t->print("$pass"); 
    $t->waitfor('/Password:$)/'); 
    $t->print("$pass2"); 
    $t->waitfor('/%$/'); 
    $t->cmd('mml'); 
    $t->waitfor('/>$/'); 
    my @out=$t->cmd(String=>'rtrv-ne',Prompt=>'/>$/'); 
    my @matches = grep {/[A-Z]BY/} @out;  
    my $line = $matches[0] if @matches or die "can't find parameters specified"; 
    $t->cmd("quit"); 
    $t->waitfor('/%$/'); 
    $t->cmd("exit"); 
    print "$line\n" Image

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

regular expression for replacing the fist word with a last word in line

I have a File with the below contents File1 I have no prior experience in unix. I have just started to work in unix. My experience in unix is 0. My Total It exp is 3 yrs. I need to replace the first word in each line with the last word for example unix have no prior experience in... (2 Replies)
Discussion started by: kri_swami
2 Replies

2. Shell Programming and Scripting

awk + pattern search with regular expression

Hi , I have a file with "|" (pipe) as a delimeter. I am looking for the record count where 5th field is a number with 15 digit length only. all the records with above requirement is valid rest all are invalid. I need count of valid records and invalid records. Can anyone please help (9 Replies)
Discussion started by: vikash_k
9 Replies

3. Shell Programming and Scripting

How to delete the word after a regular expression

Example: Lucas RUNCYCLE Rule1 Astigmatism Robot RUNCYCLE Rule2 Jack RUNCYCLE Calendar1 June Lucy RUNCYCLE Exception4 Fear RUNCYCLE Calendar5 August In this example, how can I delete the next after the expression RUNCYCLE? (i.e. Rule1, Rule2, Calendar1, Exception1, Calendar5) I'm... (3 Replies)
Discussion started by: The Gamemaster
3 Replies

4. Shell Programming and Scripting

search a regular expression and match in two (or more files) using bash

Dear all, I have a specific problem that I don't quite understand how to solve. I have two files, both of the same format: XXXXXX_FIND1 bla bla bla bla bla bla bla bla bla bla bla bla ======== (return) XXXXXX_FIND2 bla bla bla bla bla bla (10 Replies)
Discussion started by: TheTransporter
10 Replies

5. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

6. Shell Programming and Scripting

How can awk search a string without using regular expression?

Hello, Awk seem treat the pattern as regular expression, how can awk search not using regular expression? e.g. just represent for "", not "A" or "a" . I don't want to add backslash . (2 Replies)
Discussion started by: 915086731
2 Replies

7. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

8. Shell Programming and Scripting

Perl regular expression

Hi , I have the below array my @actionText = ("delivered to governor on 21/23/3345" , "deliver jllj" , "ram 2345/43"); When i am trying to grep the contents of array and if mathced substituting with the digitis or some date format from the element like below my @action = grep { $_ =~... (7 Replies)
Discussion started by: ragilla
7 Replies

9. Shell Programming and Scripting

Pattern search (regular expression in UNIX)

Hello , Could anyone help me to define the string in regular expression way . Below is my string \rtf1\ansi\deff0{\fonttbl{\f0\fswiss Helv;}{\f1\fnil MS Sans Serif;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\lang1033\f0\fs16 The string will always start as \rtf1 and... (6 Replies)
Discussion started by: Pratik4891
6 Replies

10. Shell Programming and Scripting

awk regular expression search

Hi All, I would like to search a regular expression by passing as an i/p variableto AWK. For Example :: 162.111.101.209.9516 162.111.101.209.41891 162.111.101.209.9516 162.111.101.209.9517 162.111.101.209.41918 162.111.101.209.9517 162.111.101.209.41937 162.111.101.209.41951... (7 Replies)
Discussion started by: Girish19
7 Replies
rcinet(8)						      System Manager's Manual							 rcinet(8)

NAME
rcinet - Restarts, starts, or stops Internet network services on the system SYNOPSIS
/usr/sbin/rcinet option OPTIONS
You must specify one of the following options with the rcinet command: Restarts the network on the system. Starts the network on the sys- tem. Stops the network on the system. You can restrict the restart, start, or stop operation to either IPv4 or IPv6 networks by specifying inet or inet6, respectively, as the second parameter. By default, the script assumes both IPv4 and IPv6. DESCRIPTION
The rcinet script allows system administrators to restart, start, or stop the Internet network services on the system while it is running in multiuser mode by using one of the options. RESTRICTIONS
Superuser privilege is required. Warn users that the system is being removed from the network. File systems that were not mounted using the /etc/fstab file or the automount command must be unmounted with the umount command. You must remount these file systems using the mount command after the network is started on your system. ERRORS
The rcinet script prints an error message to stderr if the network is not configured on the system. FILES
The network shell scripts are located in /sbin/init.d with symbolic links in /sbin/rc0.d and /sbin/rc3.d. SEE ALSO
Commands: mount(8) Network Administration rcinet(8)
All times are GMT -4. The time now is 11:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy