Read latest log files and perform database insert


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read latest log files and perform database insert
# 1  
Old 06-15-2017
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 database insert.
3. Log files are regularly changing and rotating, so how can we pointing the current logfile seamlessly

For Eg.
Lets say the log directory is /var/log
Log Files:
Code:
app-log0
app-log1
app-log2
...

Now the shell script has to read the latest logfile "app-log2" continuously and capture if "Success" OR "Failure" is coming. If it find it, perform the insert into a database table :

Code:
Insert into log_capture ...

And if a new log file created say "app-log3", it should start reading that log file and perform the same activity.

I know we can use tail -f that can continuously read a file, but I am not sure
1. how can I perform the database insert operation in between, whenever I get Success/Failure
2. How can "tail" pick a new file if the current file exhausted.

Any other suggestion/command is also welcome.

Thank you so much in advance.

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 06-15-2017 at 02:14 PM.. Reason: AddedCODE tags.
# 2  
Old 06-15-2017
That "reading continuously" doesn't sound feasible, and I don't see the advantage of doing so. Why don't you run a (set of) script periodically, check for old and new log files, and then insert a bunch of records into your DB?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Creating script to read many files and load into database via single control file

Hi, I have many files but with only 2 names , I want to load the data of that file into database through sqlldr with single control file. how can i do that ????? Example: switch_file switch_file billing_file billing_file now these files should be loaded into same database but different... (1 Reply)
Discussion started by: niti_sharma
1 Replies

2. Shell Programming and Scripting

Should pick latest file within past 3 days using UNIX script and perform steps in message below.

Hi , Can anyone help me how do perform below requirement in unix. Step1:we will receive multiple files weekly with same name(as below) in a folder(In folder we will have other files also def.dat,ghf.dat) Filenames: 1) abc_20171204_052389.dat 2)abc_20171204_052428.dat DON'T modify... (23 Replies)
Discussion started by: sunnykamal59
23 Replies

3. Shell Programming and Scripting

BASH script to read external file to perform text replacements?

Hi all, I have a moderate size (300 lines) BASH Shell script that performs various tasks on different source reports (CSV files). One of the tasks that it performs, is to use SED to replace 'non-conforming' titles with conformant ones. For example "How to format a RAW Report" needs to become... (3 Replies)
Discussion started by: richardsantink
3 Replies

4. Shell Programming and Scripting

Parse log file to insert into database

I have a log file that's created daily by this command: sar -u 300 288 >> /var/log/usage/$(date "+%Y-%m-%d")_$(hostname)_cpu.log It that contains data like this: Linux 3.16.0-4-amd64 (myhostname) 08/15/2015 _x86_64_ (1 CPU) 11:34:17 PM CPU %user %nice ... (12 Replies)
Discussion started by: unplugme71
12 Replies

5. 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

6. 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

7. Shell Programming and Scripting

How to read log files from last read

Hi i am looking a way to look at a log file(log.txt) from the last time I've read it. However after some days the main log file(log.txt) is rename to (log.txt.1). So now i will have two log files as below. log.txt.1 log.txt Now, i have to read the log from the point where i have left... (3 Replies)
Discussion started by: sumitsks
3 Replies

8. Shell Programming and Scripting

Insert value of vmstat to database.

Hi guys , I m trying to store the output of vmstat 1 10 into a database. I have done the necessary homework to connect bash to interact with the database. Program logic. 1)storing the output of vmstat 1 10 to a file named abc.txt 2)I m applying a filter to vmstat to get desired output... (4 Replies)
Discussion started by: pinga123
4 Replies

9. 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

10. Shell Programming and Scripting

Compare log files and get latest

I have a directory location where in some logs gets generated whenever some application build is triggered. I need to send the generated log as an email to end user. I will get files like abcyyyy_mm_dd_time.log and next file will have different time for same day. Need to run a cron and take the... (18 Replies)
Discussion started by: yogi90
18 Replies
Login or Register to Ask a Question