Parsing a log file and creating a report script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing a log file and creating a report script
# 8  
Old 08-16-2017
How about
Code:
awk -F"\.\.+"   '
BEGIN           {HD = "Device	Manufacturer	Machine Type and Model	FRU Number	Serial Number	Part Number"
                 for (MX=n=split (HD, HDArr, "\t"); n>0; n--)   {SRCH[HDArr[n]]
                                                                 LNG[n] = length(HDArr[n])
                                                                }
                }

/^(SYSTEM|MODEL|PROCESS|NUMBER)/ 

!LEADINDONE &&
!NF             {LEADINDONE    = 1
                 print
                 print HD
                 gsub (/[^\t]/, "-", HD)
                 print HD
                }
!LEADINDONE     {next
                }

NF == 1         {TMPL = RES[HDArr[4]] RES[HDArr[5]] RES[HDArr[6]]
                 if (TMPL != "") for (i=1; i<=MX; i++) printf "%-*s%s", LNG[i], RES[HDArr[i]]?RES[HDArr[i]]:"NA", (i == MX)?ORS:OFS
#                       else     delete CNT[TMPCNT]
                 split ("", RES)
                 split ($0, T, " ")
                 RES[HDArr[1]] = T[1]
                 TMPCNT = T[1]
                 sub (/[0-9]*$/, _, TMPCNT)
                 CNT[TMPCNT]++
                }

NF < 2          {next
                }

                {sub (/^ */, "", $1)
                }

$1 in SRCH      {RES[$1] = $NF
                }

END             {for (i=1; i<=MX; i++) printf "%-*s%s", LNG[i], RES[HDArr[i]]?RES[HDArr[i]]:"NA", (i == MX)?ORS:OFS
                 printf RS
                 for (c in CNT) print "Total", c, ":", CNT[c]
                }

' OFS="\t" file
SYSTEM: nb11cu51
MODEL, TYPE, and SN: IBM,9026-P70,01100699F
PROCESSOR TYPE: PowerPC_RS64-II
NUMBER OF PROCESSORS: 4

Device    Manufacturer    Machine Type and Model    FRU Number    Serial Number    Part Number
------    ------------    ----------------------    ----------    -------------    -----------
rmt0  	EXABYTE     	IBM-20GB              	59H4120   	60171713     	59H4117    
rmt1  	IBM         	03570C11              	NA        	0000000A6844 	NA         
ssa0  	IBM053      	NA                    	 34L5318  	S0237219     	 09L569B   
ssa1  	IBM053      	NA                    	 34L5388  	S0270187     	 09L5695   
rmt1  	IBM         	03570C11              	NA        	0000000A6844 	NA         
hdisk0	IBM         	DNES-309170W          	25L3101     	AJJ55889     	25L1861     
hdisk1	SEAGATE     	DPSS-309170N          	07N3675     	ZD11B560     	07N3721     
pdisk0	IBM         	DRVC09B               	NA        	680BA636SA   	34L8483     
pdisk01	MAC         	DRVC09A               	NA        	680BA636TT   	34L8483     

Total	rmt	:	3
Total	pdisk	:	2
Total	ssa	:	3
Total	pci	:	2
Total	hdisk	:	2
Total	tmscsi	:	2

The total counts are at the end as they are available only then; the reason pci and tmscsi counts are shown is that your input file does NOT stick to a reasonable structure (if you remove the # from the delete CNT line, ssa count will disappear as well...).
# 9  
Old 08-22-2017
Quote:
Originally Posted by amir07
all devices with manufacturer name, seriall number and part number need to be reported!


Code:
for h in nb11cu51
do
ssh root@$h lsattr -Elsys0 | awk -v h=$h '...

Instead of working hard to parse the output of the generic lsattr command why don't you use its abilities to display only the things you want to know?

From the man page of lsattr:
Quote:
-F Format Displays the output in a user-specified format, where the Format parameter is a quoted list of column names separated by nonalphanumeric characters or white space. If white space is used as the separator, the lsattr command displays the output in aligned columns. Only column names from the Predefined Attributes (PdAt), Customized Attributes (CuAt), and the Extended Predefined Attributes (PdAtXtd) object classes can be specified. In addition to the column names, there are two special purpose names that can be used: the name description can be used to obtain a display of attribute descriptions and user_settable can be used to determine whether an attribute can be changed. This flag cannot be used with the -E, -D, -O, or -R flag.

-a Attribute Displays information for the specified attributes of a specific device or type of device. You can use one -a flag for each attribute name or multiple attribute names. If you use one -a flag for multiple attribute names, the list of attribute names must be enclosed in quotation marks with spaces between the names. If you use the -R flag, you must specify only one -a flag with only one attribute name. If you do not specify either the -a or -R flag, the lsattr command displays all information for all attributes of the specified device. The -a Attribute flag cannot be used with the -o Operation flag. This combination of flags causes the lsattr command to exit with an error message.
I hope this helps.

bakunin

Last edited by bakunin; 08-22-2017 at 09:43 AM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with awk script parsing log file

Hello All, I am trying to parse a log file and i got this code from one of the good forum colleagues, However i realised later there is a problem with this awk script, being naive to awk world wanted to see if you guys can help me out. AWK script: awk '$1 ~ "^WRITER_" {p=1;next}... (18 Replies)
Discussion started by: Ariean
18 Replies

2. Shell Programming and Scripting

Shell script for creating log file and sending mail?

Hi , I am trying to create shell script which will help me to compare file name in two folder. There is a multiple file store in 2 folder.I want to compare that with the name. If all the file are same then send a mail that "all date is same" if not then create one log file which contain... (4 Replies)
Discussion started by: san_dy123
4 Replies

3. Shell Programming and Scripting

Parsing with Name value pair and creating a normalized file

I have url string as follows and I need to parse the name value pair into fields /rows event_id date time payload 1329130951 20120214 22.30.40... (1 Reply)
Discussion started by: smee
1 Replies

4. Shell Programming and Scripting

Script for Parsing Log File

Working on a script that inputs an IP, parses and outputs to another file. A Sample of the log is as follows: I need the script to be able to input IP and print the data in an output file in the following format or something similar: Thanks for any help you can give me! (8 Replies)
Discussion started by: Winsarc
8 Replies

5. UNIX for Dummies Questions & Answers

Creating a report from csv file.

Hi Gurus, I need your help in transforming the CSV file into some what a report format. My source file looks like below Date,ProdID,TimeID,LevelID 2010-08-31,200,M,1 2010-08-31,201,Q,2 2010-08-31,202,Y,1 2010-08-31,203,M,5 Output required is ... (9 Replies)
Discussion started by: naveen.kuppili
9 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

8. Shell Programming and Scripting

Help with script parsing a log file

I have a large log file, which I want to first use grep to get the specific lines then send it to awk to print out the specific column and if the result is zero, don't do anything. What I have so far is: LOGDIR=/usr/local/oracle/Transcription/log ERRDIR=/home/edixftp/errors #I want to be... (3 Replies)
Discussion started by: mevasquez
3 Replies

9. Shell Programming and Scripting

Shell script for parsing 300mb log file..

am relatively new to Shell scripting. I have written a script for parsing a big file. The logic is: Apart from lot of other useless stuffs, there are many occurances of <abc> and corresponding </abc> tags. (All of them are properly closed) My requirement is to find a particular tag (say... (3 Replies)
Discussion started by: gurpreet470
3 Replies

10. Shell Programming and Scripting

Help with a shell script for creating a log file

I have a schell script that runs continously on an AIX system. It is actually started from another shell script with the "ksh -x" command and then I just write the output to a log file. This causes the log files to be filled with mostly useless information. I would like to modify this script to... (2 Replies)
Discussion started by: heprox
2 Replies
Login or Register to Ask a Question