Sponsored Content
Top Forums Shell Programming and Scripting Parse log file to insert into database Post 302952238 by Scrutinizer on Sunday 16th of August 2015 05:38:32 AM
Old 08-16-2015
IMO if you are only going to represent %system %user and %idle, you cannot simply discard the columns, you need to map the other columns by adding them to the relevant columns.

For example %iowait is idle time, while IO is happening, but it is still idle time, so you need to add it to idle time, otherwise the numbers do not add up to 100%.
In your sample the percentages are low, but there are situations where they may be significant.

I think you should use this:
Code:
%total_user = %user + %nice 
%total_idle = %iowait + %steal + %idle

So, adjusting Don's suggestion that would mean:
Code:
	print FNR, d, $1 " " $2, $4+$5, $6, $7+$8+$9

Which produces the output:
Code:
4|2015-08-14|11:39:17 PM|0.09|0.07|99.84
5|2015-08-14|11:44:17 PM|0.04|0.03|99.92
6|2015-08-14|11:49:17 PM|1.49|0.49|98.02
7|2015-08-14|11:54:17 PM|23.27|0.51|76.22
10|2015-08-14|11:56:12 PM|0.17|0.13|99.71
4|2015-08-15|11:39:17 PM|0.09|0.07|99.84
5|2015-08-15|11:44:17 PM|0.04|0.03|99.92
6|2015-08-15|11:49:17 PM|1.49|0.49|98.02
7|2015-08-15|11:54:17 PM|23.27|0.51|76.22
10|2015-08-15|11:56:12 PM|0.17|0.13|99.71

This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to insert data in database based on text file?

Hi....can you guys help me out in this script?? Below is a text file script....called Bukom.txt and it contains these: BUKOM 20060101 2.5 2.6 2.7 2.8 2.9 2.3 2.1 BUKOM 20060102 2.4 2.5 2.6 2.7 2.7 2.6 2.4 BUKOM 20060103 2.1 ... (9 Replies)
Discussion started by: forevercalz
9 Replies

2. Shell Programming and Scripting

How to insert data into MYSql database from a text file

Hi, Need to get help from you guys about this issue. I need to insert data into MySql database from a text file which is located in other server. The text file is something look like below: Date | SubscriberNo | Call Duration 20/7/07 | 123456788 | 20 20/7/07 | 123412344 | 30 The... (4 Replies)
Discussion started by: shirleyeow
4 Replies

3. Shell Programming and Scripting

how to insert data into database by reading it from a text file??

Hi....can you guys help me out in this script?? Below is a text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (4 Replies)
Discussion started by: pallavishetty
4 Replies

4. Shell Programming and Scripting

Shell script to parse a line and insert a word

Hi All, I have a file like this, data1,data2,,,data5,data6. i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this . data1,data2,example/string],,data5,data6. Could you guys help me to get a sed command or any other command... (8 Replies)
Discussion started by: girish.raos
8 Replies

5. Shell Programming and Scripting

To Read a File and Insert a part of the lines into the database

Hi Guys I need to have a shell script which reads a log file and insert a part of each line into the database. Some sample lines in the file are as below. 20091112091359 MED_RQACK : user_data=60173054304,100232120,20091112091359,;ask_status=0;ask_reason=OK;msg_id=20091112091319... (5 Replies)
Discussion started by: Somanadh
5 Replies

6. Web Development

INSERT data to a Database Table from a text file

If you have a text file and if you want to Insert data to your Database Table, You can do it with these queries LOAD DATA LOCAL INFILE '/path/yourTextFile.txt' INTO TABLE yourTableName FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' (0 Replies)
Discussion started by: sitex
0 Replies

7. Shell Programming and Scripting

Korn shell program to parse CSV text file and insert values into Oracle database

Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database. I need to write the korn shell program on Red Hat Enterprise Linux server. Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies

8. Shell Programming and Scripting

Parse through ~21,000 Database DDL statements -- Fastest way to perform search, replace and insert

Hello All: We are looking to search through 2000 files with around 21,000 statements where we have to search, replace and insert a pattern based on the following: 1) Parse through the file and check for CREATE MULTISET TABLE or CREATE SET TABLE statements.....and they always end with ON... (5 Replies)
Discussion started by: madhunk
5 Replies

9. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

10. Shell Programming and Scripting

Read latest log files and perform database insert

Hi Experts, I have a situation where I need to write a shell script to continuously monitor a log directory with multiple log files and perform following: 1. Read the latest log file continuously and grep "Success" OR "Failure" 2. As it capture either Success or Failure, it has to perform a... (1 Reply)
Discussion started by: rish_max
1 Replies
SA2(8)								Linux User's Manual							    SA2(8)

NAME
sa2 - Write a daily report in the /var/log/sysstat directory. SYNOPSIS
/usr/lib/sysstat/sa2 DESCRIPTION
The sa2 command is a shell procedure variant of the sar command which writes a daily report in the /var/log/sysstat/sardd file, where the dd parameter indicates the current day. The sa2 command handles all of the flags and parameters of the sar command. The sa2 command is designed to be started automatically by the cron command. EXAMPLES
To run the sa2 command daily, place the following entry in your root or adm crontab file: 5 19 * * 1-5 /usr/lib/sysstat/sa2 -A & This will generate a daily report called /var/log/sysstat/sardd It will also remove reports more than one week old. Debian note The Debian sysstat package has already placed such an entry in your system crontab. Please refer to the /usr/share/doc/sys- stat/README.Debian file for details. FILES
/var/log/sysstat/sardd Indicate the daily report file, where the dd parameter is a number representing the day of the month. AUTHOR
Sebastien Godard (sysstat <at> orange.fr) SEE ALSO
sar(1), sadc(8), sa1(8), sadf(1) http://pagesperso-orange.fr/sebastien.godard/ Linux AUGUST 2010 SA2(8)
All times are GMT -4. The time now is 09:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy