{How} Script to search a log file for a given criteria


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting {How} Script to search a log file for a given criteria
# 1  
Old 08-04-2008
{How} Script to search a log file for a given criteria

I have to write a script to search the logfiles i.e msg.log for the following
The Search Criteria is as follows

1. IP address

2. String
Ex: abc.123.com

3. Timestamp ( start - end )
ex: 2008-05-04-00:30:00 - 2008-05-08-04:30:00

Can anyone help to devise a script for the above requirement please?
# 2  
Old 08-04-2008
Question Really need to see a section of the log file

From what you gave, it would be difficult to write commands. For instace, does all of that information exist on one line or in some kind of 'block'? And, what is the desired output format?
# 3  
Old 08-04-2008
Quote:
Originally Posted by joeyg
From what you gave, it would be difficult to write commands. For instace, does all of that information exist on one line or in some kind of 'block'? And, what is the desired output format?
Hi,
I want it to be step by step for example
I would want it to ask the Ip address

1.IP address ?
192.198.12.1

Then.

2. String ?

abc.123.com

Then it would ask me the timestamp

3 Timestamp Start : 2008-08-04-00:30:00
End : 2008-08-04-04:30:00
# 4  
Old 08-04-2008
Question Asking questions is fairly simple. But what doe sth datafile look like?

You want to search a datafile. Typically, datafiles are in one of the following two general formats:

(a)
ip 123.123.123.123 joe.123.com 10:00:00:00 11:30:00:00
etc...
or (b)
ip_value = 123.123.123.123
<begin>
name = joe.123.com
begin_time = 10:00:00:00
end_time = 11:30:00:00
<end>
ip_value = 109.110.111.112
etc...
# 5  
Old 08-04-2008
Quote:
Originally Posted by joeyg
You want to search a datafile. Typically, datafiles are in one of the following two general formats:

(a)
ip 123.123.123.123 joe.123.com 10:00:00:00 11:30:00:00
etc...
or (b)
ip_value = 123.123.123.123
<begin>
name = joe.123.com
begin_time = 10:00:00:00
end_time = 11:30:00:00
<end>
ip_value = 109.110.111.112
etc...
-------------------------------------------------

Hi

Its a log file in the following format

(a)
ip 123.123.123.123 joe.123.com 10:00:00:00 11:30:00:00
etc...

Thank you
# 6  
Old 08-04-2008
Quote:
Originally Posted by indiakingz
-------------------------------------------------

Hi

Its a log file in the following format

(a)
ip 123.123.123.123 joe.123.com 10:00:00:00 11:30:00:00
etc...

Thank you

The format of the log is exactly as follows

131.161.141.101 - 123@abc.com [04/Aug/2008:09:49:07 -0400] "GET /apiserv/off.do?PAS=LA,,&refID=1217857747724_6550201 HTTP/1.1" 302 0


Thanks Again
# 7  
Old 08-04-2008
Hammer & Screwdriver Here is the start then

Code:
#! /usr/bin/bash
# get the variables
echo -n "1. IP address ? "
read ip_addr
echo -n "2. String ? "
read website
echo -n "3a. Timestamp start = "
read time_st
echo -n "3b. Timestamp end = "
read time_en
# search the file
cat myfile | grep ip_addr
#and so one from here

There is more to do at the end here, but without seeing the datafile and knowing exactly what you are looking for as output, I do not know what to tell you to do.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to search log file for last 15 mins data

Hi All, I have an issue which I'm trying to understand a way of doing, I have several nodes which contain syslog events which I want to force trigger an email initially (eventually leading to another method of alerting but to start with an email). Basically the syslog file will have hours worth... (6 Replies)
Discussion started by: mutley2202
6 Replies

2. Shell Programming and Scripting

Script to search for a pattern in 30 minutes from a log file

Hello All, I have to write a script which will search for diffrent patterns like "Struck" "Out of Memory" , etc from a log file in Linux box's. Now I will be executing a cron job to find out the results by executing the script once in every 30 minutes. suppose time is 14-04-29:05:31:09 So I... (3 Replies)
Discussion started by: Shubhasis Mathr
3 Replies

3. Shell Programming and Scripting

Copying section of file based on search criteria

Hi Guru's, I am new to unix scripting. I have a huge file with user details in it(file2) and I have another file with a list of users(file1). Script has to search a user from file1 and get all the associated lines from file2. Example: fiel1: cn=abc cn=DEF cn=xyx File 2: dn:... (10 Replies)
Discussion started by: Samingla
10 Replies

4. Shell Programming and Scripting

How can I search with start and end criteria?

Hello I'm using cygwin and wouldlike extract information from an xml file according specific values, but don't know how. Let's say in a file content looks like this: <tab> SURNAME=Mustermann NAME=Max CUSTOMER SINCE= 18.01.2000 ADDRESS=Birmingham ... (2 Replies)
Discussion started by: witchblade
2 Replies

5. Shell Programming and Scripting

Need To Delete Lines Based On Search Criteria

Hi All, I have following input file. I wish to retain those lines which match multiple search criteria. The search criteria is stored in a variable seperated from each other by comma(,). SEARCH_CRITERIA = "REJECT, DUPLICATE" Input File: ERROR,MYFILE_20130214_11387,9,37.75... (3 Replies)
Discussion started by: angshuman
3 Replies

6. Shell Programming and Scripting

Extract data based on specific search criteria

I have a huge file (about 2 millions records) contains data separated by “,” (comma). As part of the requirement, I can't change the format. The objective is to remove some of the records with the following condition. If the 23rd field on each line start with 302 , I need to remove that from the... (4 Replies)
Discussion started by: jaygamini
4 Replies

7. Shell Programming and Scripting

awk search & delete located criteria

Guys, I manages to get awk to search and print the files that I want to delete. However I am stuck on the delete portion. Here is the command that I am using to fins these files. find /usr/local/apache/conf/vhosts/ -type f | awk '/e$/' The output is perfect. The files look like so: ... (4 Replies)
Discussion started by: jaysunn
4 Replies

8. Shell Programming and Scripting

Delete new lines based on search criteria

Hi all! A bit of background: I am trying to create a script that formats SQL statements. I have gotten so far as to add new lines based on certain match criteria like commas, keywords etc. In the process, I end up adding newlines where I don't want. For example: substr(colName, 1, 10)... (3 Replies)
Discussion started by: jayarkay
3 Replies

9. Shell Programming and Scripting

Append specific lines to a previous line based on sequential search criteria

I'll try explain this as best I can. Let me know if it is not clear. I have large text files that contain data as such: 143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13... (3 Replies)
Discussion started by: jesse
3 Replies

10. UNIX for Dummies Questions & Answers

Select records based on search criteria on first column

Hi All, I need to select only those records having a non zero record in the first column of a comma delimited file. Suppose my input file is having data like: "0","01/08/2005 07:11:15",1,1,"Created",,"01/08/2005" "0","01/08/2005 07:12:40",1,1,"Created",,"01/08/2005"... (2 Replies)
Discussion started by: shashi_kiran_v
2 Replies
Login or Register to Ask a Question