{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
# 8  
Old 08-04-2008
Quote:
Originally Posted by joeyg
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.
---------------------------------------------------------------------

Thanks once again,

The 10 lines of the data file would be as follows,

71.25.79.95 - jle@gmail.com [04/Jul/2008:18:27:59 -0400] "GET HTTPS://aer.seal.com/bps/sortal/myse...lWaitCounter=1 HTTP/1.0" 200 9104
4.24.22.20 - Unauth [04/Jul/2008:18:27:59 -0400] "GET HTTPS://link1.seal.com/images/general/MovingArrows_anim_5.gif HTTP/1.1" 200 266
168.131.19.2 - Unauth [04/Jul/2008:18:27:57 -0400] "GET HTTPS://link1.seal.com/un/fw/def/style/forms.css HTTP/1.1" 200 7701
110.1.167.11 - kat13@gmail.com [04/Jul/2008:18:27:59 -0400] "GET HTTPS://bull.seal.com/bps/sortal/mys...lttCounter%3D1 HTTP/1.1" 200 9645
167.187.15.22 - mam@gmail.com [04/Jul/2008:18:27:57 -0400] "GET HTTPS://linkcentl1.seal.com/static/images/loading.gif HTTP/1.1" 200 1277
175.150.23.5 - Unauth [04/Jul/2008:18:27:59 -0400] "GET HTTPS://linkcentra.seal.com/favicon.ico HTTP/1.1" 302 1946
199.113.1.18 - Unauth [04/Jul/2008:18:27:59 -0400] "GET HTTPS://link1.seal.com/ls_launch_error.jsp HTTP/1.1" 302 1946
176.129.27.154 - Unauth [04/Jul/2008:18:28:00 -0400] "GET HTTPS://link1.seal.com/un/images/gen...ttom_right.gif HTTP/1.1" 200 52
168.122.20.213 - Unauth [04/Jul/2008:18:27:59 -0400] "GET HTTPS://link1.seal.com/un/fw/def/jscript/tabset.js HTTP/1.1" 304 0


What i am trying to do is to get THE logs from a particular IPADDRESS and/or String ( which can be the email ID or the ones marked in RED ) and/or the Time frame attached to it just by running the script.

For example I expect the script to ask me the 1.

1.Ip address and for example if I give the one above 167.187.15.22

2.Then I expect it to ask the string and IF I GIVE mam@gmail.com

3.Then I need the script to ask me for the timeframe

and all the above should be CASE STATEMENTS,

and it would give me the result as follows

167.187.15.22 - mam@gmail.com [04/Jul/2008:18:27:57 -0400] "GET HTTPS://linkcentl1.seal.com/static/images/loading.gif HTTP/1.1" 200 1277

Thanks again
# 9  
Old 08-05-2008
Quote:
Originally Posted by joeyg
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.
---------------------------------------------------------------------

Hi,

Following are the 10 lines of a data file,

255.45.250.227 - Unauth [05/Aug/2008:20:47:05 -0400] "GET HTTPS://relia.stage.tata.com/un/imag...xplorebg_h.gif HTTP/2.2" 504 0
255.45.250.227 - Unauth [05/Aug/2008:20:47:05 -0400] "GET HTTPS://relia.stage.tata.com/un/images/nav/white.gif HTTP/2.2" 504 0
255.45.250.227 - Unauth [05/Aug/2008:20:47:05 -0400] "GET HTTPS://relia.stage.tata.com/images/general/blank.gif HTTP/2.2" 504 0
244.258.27.225 - airtel1@tata.net [05/Aug/2008:20:47:05 -0400] "GET HTTPS://test-Sky.stage.tata.com/stat...et_orange2.gif HTTP/2.2" 200 55
244.258.27.225 - airtel1@tata.net [05/Aug/2008:20:47:05 -0400] "GET HTTPS://test-Sky.stage.tata.com/static/js/mam_popup.js HTTP/2.2" 200 650
255.45.250.227 - Unauth [05/Aug/2008:20:47:05 -0400] "GET HTTPS://relia.stage.tata.com/include...Javascript.jsp HTTP/2.2" 200 46850
255.45.250.227 - Unauth [05/Aug/2008:20:47:05 -0400] "GET HTTPS://relia.stage.tata.com/un/js/browsercheck.js HTTP/2.2" 504 0
244.258.27.225 - airtel1@tata.net [05/Aug/2008:20:47:05 -0400] "GET HTTPS://test-Sky.stage.tata.com/stat...m_writeHTML.js HTTP/2.2" 200 2702
255.45.250.227 - Unauth [05/Aug/2008:20:47:05 -0400] "GET HTTPS://relia.stage.tata.com/un/js/general.js HTTP/2.2" 504 0
255.45.250.227 - Unauth [05/Aug/2008:20:47:04 -0400] "GET HTTPS://relia.stage.tata.com/un/js/lsgeneralScripts.js HTTP/2.2" 504 0


I would ideally like the script to ask the ipaddress first FOR EXAMPLE

>>> 1.Enter IP address - 244.258.27.225

( In case we dont want to search or get info using IPADDRESS then I would want the Script to bypass )


Then I would like the script to ask me to input a string,

>>> 1.Enter String - airtel1@tata.net

( In case we dont want to search or get info using String then I would want the Script to bypass )


Then I would like the script to ask me to ask for the Timestamp

>>> 1. Enter timestamp - Start [05/Aug/2008:20:45:00] - End [05/Aug/2008:20:50:00]

( In case we dont want to search or get info using Logfiles then I would want the Script to bypass )


and basing on the above info I would like the script to get


244.258.27.225 - airtel1@tata.net [05/Aug/2008:20:47:05 -0400] "GET HTTPS://test-Sky.stage.tata.com/stat...et_orange2.gif HTTP/2.2" 200 55
244.258.27.225 - airtel1@tata.net [05/Aug/2008:20:47:05 -0400] "GET HTTPS://test-Sky.stage.tata.com/static/js/mam_popup.js HTTP/2.2" 200 650
244.258.27.225 - airtel1@tata.net [05/Aug/2008:20:47:05 -0400] "GET HTTPS://test-Sky.stage.tata.com/stat...m_writeHTML.js HTTP/2.2" 200 2702

Thanks a lot again
# 10  
Old 08-05-2008
Looking like homework...

Since this post here, and
https://www.unix.com/shell-programmin...#post302221945

look VERY similar, it appears that this is homework.
That is not allowed under forum rules.

Explain if otherwise.
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