Sponsored Content
Top Forums Shell Programming and Scripting Read latest log files and perform database insert Post 302999224 by rish_max on Thursday 15th of June 2017 12:16:00 PM
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.
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
ncalogd.conf(4) 						   File Formats 						   ncalogd.conf(4)

NAME
ncalogd.conf - NCA logging configuration file SYNOPSIS
/etc/nca/ncalogd.conf DESCRIPTION
The ncalogd.conf is used to configure Solaris Network Cache and Accelerator ("NCA") logging. The file contains two fields, key and value. The status key is used to indicate if the user wants to have NCA logging turned on. If the value of status key is enabled, then NCA logging will be turned on. If the value of the status key is disabled, then NCA logging will not be invoked. The default value is disabled. The logd_path_name key specifies the absolute pathname of the log file. The log file must be a raw device without a filesystem or a file on a local file system. The default value is /var/nca/log. logd_path_name can also contain a whitespace-delimited list of values for multiple log files to a maximum of 16. If you specify multiple log files, you must enclose the list in quotation marks ("). With multiple files, NCA logging moves to the next file on the list once the file size specified by logd_file_size has been reached. When the last file is full, NCA logging rotates back to the first file in the list. A pointer to the current log file is stored in /var/nca/current. The logd_file_size key specifies the value of the file size, in bytes, allowed for each log file specified in by the logd_path_name key. The default value is 1000000 bytes. In order to implement changes to the ncalogd.conf file, you will need to stop and start NCA logging or reboot. NCA stores logs in a binary format. Use the ncab2clf(1) utility to convert the log from a binary format to the Common Log File format. EXAMPLES
Example 1 A Sample ncalogd.conf File The following is a sample ncalogd.conf file that specifies three log files: # # NCA Log Daemon Configuration File # status=enabled logd_path_name="/var/nca/log1 /var/nca/log2 /var/nca/log3" logd_file_size=1000000 Note that there is no NCA logging daemon. Logging is performed as one of the functions of the NCA software. FILES
/etc/nca/ncalogd.conf Lists configuration parameters for NCAlogging. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWncar | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
nca(1), ncab2clf(1), ncakmod(1), dd(1M), door_create(3C), nca.if(4), ncakmod.conf(4), attributes(5) System Administration Guide: IP Services SunOS 5.11 22 Jan 2002 ncalogd.conf(4)
All times are GMT -4. The time now is 10:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy