Sponsored Content
Top Forums Shell Programming and Scripting {How} Script to search a log file for a given criteria Post 302221849 by indiakingz on Tuesday 5th of August 2008 11:05:00 AM
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 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 01:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy