Sponsored Content
Top Forums Shell Programming and Scripting Read log file to create Performance index Post 302957463 by Don Cragun on Sunday 11th of October 2015 04:35:33 PM
Old 10-11-2015
I don't think RudiC's suggestion is going to work since you want separate counts of the number of lines containing each of the three strings, not a total of number of lines that contain one or more of the strings.

Since you have specified that the name of the log file to be processed is the empty string (not the name of a file), jim mcnamara's script won't work either. And, if you did provide the name of your log file, getting the last 200000 lines three times (while additions are being added to the log file by other processes) means that it will run slow and give you counts for the three strings from different sets of lines in your file. It is also dangerous to expand a variable without double quoting it if there is ANY possibility that it could contain whitespace characters, characters that are special in pathname expansions, or (as in this case) an empty string.

I would be tempted to try something more like:
Code:
#!/bin/bash

foldername=$(date +%Y%m%d)
LOG_NAME="/path/to/your/logfile"
mkdir -p  /root/kpi/"$foldername"

tail -200000 "$LOG_NAME" | awk -v ts=$(date +%Y/%m/%d/%H/%M) '
	/ACCESS_REQUEST/{ a++ }
	/ACCESS_ACCEPT/	{ b++ }
	/ACCESS_REJECT/	{ c++ }
	END 		{ printf("%d,%d,%d,%s\n", a, b, c, ts) }
' >> /root/kpi/"$foldername/kpi_$foldername.csv"

This only reads the log file once and gathers individual counts for each string, but you still have to fill in the real name of the log file this script is supposed to process.

And, as always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.

Last edited by Don Cragun; 10-14-2015 at 04:01 PM.. Reason: Add missing quotes.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read words from file and create new file using K-shell.

Hi All, Please help me in creating files through K-shell scripts. I am having one file in this format. OWNER.TABLE_NAME OWNER.TABLE_NAME1 OWNER1.TABLE_NAME OWNER1.TABLE_NAME1 I want to read the above file and create new file through k shell script. The new file should looks like this.... (4 Replies)
Discussion started by: bsrajirs
4 Replies

2. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

3. Shell Programming and Scripting

read mp3 filename and create one XML for each file

Hi: I have a collection of mp3s and I need to create 1 xml file per mp3. I have: recording1.mp3 recording2.mp3 etc and I want to generate this kind of files. recording1.xml recording2.xml and inside each xml file I need to add a url prefix and then the filename at the end. ... (4 Replies)
Discussion started by: jason7
4 Replies

4. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies

5. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

6. Shell Programming and Scripting

Read a file and create egrep variable

I want to create a egrep variable from a file. For example: string=`cat query.txt` cat myfile.txt | egrep "$string" The string variable file has a list of one or multiple lines So the end result of: cat myfile.txt | egrep "$string" would be: cat myfile.txt | egrep... (2 Replies)
Discussion started by: numele
2 Replies

7. Shell Programming and Scripting

Linux Script create index.html file

I need a script that can do this: A script that searches all directories and subdirectories for .html files When a .html file is found it creates a index.html file in that folder. It then edits the index.html file and inserts links to all of the .html files that are in that folder into the... (5 Replies)
Discussion started by: seashell11
5 Replies

8. UNIX for Dummies Questions & Answers

create table file from different files with index

Hi, I've several files with two collumns, where first collumn can be used as index. filename1 and filename2 how to create a file I should start with cat all files and extract first collumn to create an index? (4 Replies)
Discussion started by: sargotrons
4 Replies

9. UNIX for Dummies Questions & Answers

Filter logs for key words and create an index

well, im a total novice of unix commands and shell scripting, i never made anything. But yesterday in my work i was working with a lot of log files and i was wondering if there is a command for doing something like this: i have a bunch of files with text like this: blablabla errorcode1... (11 Replies)
Discussion started by: matius_88
11 Replies

10. Shell Programming and Scripting

Read Lines from One file.. and create another.. and

Hello Members, I have one file which contains million of supplier code. I need to load these codes into database 1000 at a time. Database procedure reads from an external table which is based on the unix files. All I want to do is to read from the bigger file e.g. MAIN_FILE.txt and create... (1 Reply)
Discussion started by: chetanojha
1 Replies
PMDABONDING(1)						       Performance Co-Pilot						    PMDABONDING(1)

NAME
pmdabonding - Linux bonded interface performance metrics domain agent (PMDA) DESCRIPTION
pmdabonding is a Performance Metrics Domain Agent (PMDA) which exports metric values from bonded network interfaces in the Linux kernel. INSTALLATION
If you want access to the names and values for the bonding performance metrics, do the following as root: # cd $PCP_PMDAS_DIR/bonding # ./Install If you want to undo the installation, do the following as root: # cd $PCP_PMDAS_DIR/bonding # ./Remove pmdabonding is launched by pmcd(1) and should never be executed directly. The Install and Remove scripts notify pmcd(1) when the agent is installed or removed. FILES
$PCP_PMDAS_DIR/bonding/Install installation script for the pmdabonding agent $PCP_PMDAS_DIR/bonding/Remove undo installation script for the pmdabonding agent $PCP_LOG_DIR/pmcd/bonding.log default log file for error messages from pmdabonding SEE ALSO
pmcd(1) and ifenslave(8). 3.8.10 Performance Co-Pilot PMDABONDING(1)
All times are GMT -4. The time now is 09:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy