Sponsored Content
Top Forums Shell Programming and Scripting [Solved] perl and grep: get a script to look at more then one file Post 302552836 by durden_tyler on Monday 5th of September 2011 09:58:59 PM
Old 09-05-2011
Quote:
Originally Posted by ab52
...
how can i get it to look at more then one file, i.e /var/log/message.all *
so it looks in old logs as well
Code:
exit 0 if (isRenderNode(hostname));
my $PROG     = 'nvrm';
my $xorglog = '/var/log/messages.all';
my $techuser = 'caston|sutton|copdock';

if ($DNHOST !~($techuser)){
if (-e "$xorglog" ) {
    open my $xorg_log, $xorglog or die "$PROG: can't open $xorglog: $!\n";
    my @xorglog = <$xorg_log>;
    close $xorg_log;
    if (grep  { /NVRM: Xid/ } @xorglog) {
        print " Serial Tag: ";
    print `cat /tools/SITE/etc/cfg/systems/systems | grep $DNHOST | cut -d , -f 9 `;
    print " Room Number: ";
          print `cat /tools/SITE/etc/cfg/systems/systems | grep $DNHOST | cut -d , -f 3 `;
    print `dnsu dnhinv | grep -i Graphics| cut -d : -f 2\n `;
    print `dnsu dnhinv | grep -i BIOS | cut -d ] -f 2 \n`;
    print `cat $xorglog | grep "NVRM: Xid"`;
        }
   # XXX more... 
}
}

Try this (changes are in red):

Code:
exit 0 if (isRenderNode(hostname));
my $PROG     = 'nvrm';
# my $xorglog = '/var/log/messages.all';  ## comment out or delete this line
my $techuser = 'caston|sutton|copdock';

if ($DNHOST !~($techuser)){
foreach my $xorglog (glob "/var/log/messages.all-\d{8}") { # $xorglog is one file name at a time; the glob regex could be tailored to suit your need
if (-e "$xorglog" ) {
    open my $xorg_log, $xorglog or die "$PROG: can't open $xorglog: $!\n";
    my @xorglog = <$xorg_log>;
    close $xorg_log;
    if (grep  { /NVRM: Xid/ } @xorglog) {
        print " Serial Tag: ";
    print `cat /tools/SITE/etc/cfg/systems/systems | grep $DNHOST | cut -d , -f 9 `;
    print " Room Number: ";
          print `cat /tools/SITE/etc/cfg/systems/systems | grep $DNHOST | cut -d , -f 3 `;
    print `dnsu dnhinv | grep -i Graphics| cut -d : -f 2\n `;
    print `dnsu dnhinv | grep -i BIOS | cut -d ] -f 2 \n`;
    print `cat $xorglog | grep "NVRM: Xid"`;
        }
   # XXX more... 
}
}   # closing brace for the foreach loop
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep ^M in file using perl script....

hi i am using perl on windows ( active state perl 5.8 ) and i want to check for Control-M (^M) in file. files to be checked are in unix format so new line character is (\n). This perl script is called from Batch file ( windows .BAT file ) my script is while (<PROGRAM>) { ... (12 Replies)
Discussion started by: zedex
12 Replies

2. Shell Programming and Scripting

[Solved] how Execute a Perl Script from any location on the machine

hi guys, i have a query, i wrote a perl script that will collect cpu statistics Scripts/myScripts/ cpu.pl i want to make this file so that i can run it from any location on any drive, without giving the path explicitly. like $/home/ravi/perl cpu.pl i tried this... (8 Replies)
Discussion started by: niteesh_!7
8 Replies

3. Shell Programming and Scripting

SOLVED: reading config file in a perl script

Hi! I have a need to do this in Perl. script.pl -config file The script would be doing a wget/LWP on a URL which is defined in the config file. So when I run the script it should return either one of these conditions - 1) OK with exit status 0. Should also print "wget URL" 2)... (6 Replies)
Discussion started by: jacki
6 Replies

4. UNIX for Dummies Questions & Answers

SOLVED: Text file compare using perl

I have two text file.... One text file contain in this format...... keyvalue.txt \SUM\SUM_cam.c \SUM\SUM_cam.h \SUM\SUM_command.c \SUM\SUM_command.h \SUM\SUM_dab.c \SUM\SUM_dmb.c \SUM\SUM_eventHandler.h \SUM\SUM_eventHandler_dab.c \SUM\SUM_eventHandler_dmb.c ... (6 Replies)
Discussion started by: suvenduperl
6 Replies

5. Shell Programming and Scripting

Run perl command in script[solved]

Hi all, When I put the Perl command in a script, I got error. system("perl -pi -e 's@words@words@g' myFile"); The error is: Unrecognized character \x8A; marked by <-- HERE after دت مد�<-- HERE near column 15 at -e line 1. Thanks in advance. ---------- Post updated at 06:30 AM... (0 Replies)
Discussion started by: Lham
0 Replies

6. Programming

Unix grep in perl script

Hello, Fairly simple really I have an xml file and I want to check to see if it contains a pattern. The pattern is "../" On the command line I can type: grep "\.\./" myFile.xml and I get desired result. To do the same thing in a perl script I thought it was as simple as putting the ``... (4 Replies)
Discussion started by: Jaymoney
4 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Perl Question - split function with csv file

Hi all, I have a csv file that appears as follows: ,2013/03/26,2012/12/26,4,1,"2017/09/26,5.75%","2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1",,,2012/12/26,now when i use the split function like this: my @f = split/,/; the split function will split the data that is... (2 Replies)
Discussion started by: WongSifu
2 Replies

8. Shell Programming and Scripting

[Solved] Help with grep script

Hi, I'm having trouble with a script to copy one line out of multiple files in a directory and copy to a file called test. I've tried the code below but it copies one line out of the first file multiple times not one line out of all the files. Would someone help? I'm very new to all this. ... (8 Replies)
Discussion started by: bob101
8 Replies

9. UNIX for Advanced & Expert Users

[SOLVED] Grep IP's from xml with name of file

Hi all, actually i have a lot of IP addresses on multiple .xml files on my folder, my tag on xml files are like this, <db-url>jdbc:oracle:thin:@10.100.5.56:1521:DWH01</db-url> i actually can print only the IP addresses awk -F"" '/url/ { print $3 }' *.xml 10.100.5.56 i would like to grep... (2 Replies)
Discussion started by: charli1
2 Replies

10. UNIX for Dummies Questions & Answers

[Solved] Grep in bash script

Hi Experts, I'm writing script to find out last files and its modified date - unfortunately am having problem with the below script. Error message: "grep: sales.txt: No such file or directory" #!/bin/bash var=1 var1=`awk '{n++} END {print n}' sales.txt` while ] do prod=$var... (6 Replies)
Discussion started by: parpaa
6 Replies
cdslinvchk(8)						      System Manager's Manual						     cdslinvchk(8)

NAME
cdslinvchk - Checks the CDSL inventory of the base operating system and layered applications. SYNOPSIS
/usr/sbin/cdslinvchk [log_file_path] OPTIONS
The path name to a location for the log file. By default this will be /var/adm/cdsl_check_list. DESCRIPTION
Use the cdslinvchk script to verify the current inventory of Context Dependent Symbolic Links (CDSLs) on a running system. CDSLs are spe- cial symbolic links that enable a system to work in a cluster. If CDSLs are accidentally removed, your system will not function correctly in a cluster. While this is not a problem for stand-alone systems, you may not be able to add the system as a member of a working cluster at some future time. You can run this script at any time or configure it to run at system start-up, or as a cron task. When you invoke the script, it checks the CDSLs on the running system against CDSLs of the installed inventory in /usr/.smdb and the addi- tional entries in /var/adm/cdsl_admin.inv, and ensures that each target file exists on the system as a properly-constituted CDSL. If the check is successful, the following message is displayed and the script terminates: Successful CDSL inventory check If the script finds inconsistencies in the inventory, warning messages are displayed on your terminal and logged to the default log file at /var/adm/cdsl_check_list. You can specify an alternate location for the log fill if required. The script locates any modified, missing, or replaced CDSLs. Note that the previous copy of the log file is renamed and retained for reference and is renamed by appending to the filename. Refer to the System Administration guide for information on recreating any missing or broken CDSLs. Refer to the hier(5) reference page for an inventory of CDSLs. MESSAGES One or more of the following messages may be displayed and logged to the log file: Unable to create <pathname> report file -- the script was not able to create a log file. Check the target directory and security. Expected CDSL: <cdsl_pathname> -> <pathname> CDSL Target has been modified to: <pathname> CDSL has been replaced with <pathname> CDSL is missing Failed CDSL inventory check. See details in <log file> FILES
Additional inventory file entries. This file will not exist on all systems. The current and previous log files for inventory errors and messages SEE ALSO
Commands: cron(8) Others: hier(5) See also the System Administration guide for details of CDSLs cdslinvchk(8)
All times are GMT -4. The time now is 05:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy