Searching set of string from Live Running Logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching set of string from Live Running Logs
# 1  
Old 09-16-2010
Searching set of string from Live Running Logs

Hey just need one simple syntax to search for the string from the Live Running Logs. The strings are placed in a $infile & everytime the script should pull each string from $infile and should provide as an input for grepping from Live running logs on a rotational basis.

So here are the Contents of $inFile

87634863476
98349834987
98349873498
9JH83N3838
KJNE8302J3

How this can be used as an input for search string..
# 2  
Old 09-16-2010
Put it in a file:
Code:
cat SearchStrings.txt
87634863476
98349834987
98349873498
9JH83N3838
KJNE8302J3

# And after
infile="SearchStrings.txt"
logFile="RunningLog.log"
while read mLine
do
       egrep ''"${mLine}"'' "${logFile}"
done < "${infile}"

Regards!

Last edited by felipe.vinturin; 09-16-2010 at 08:27 AM..
# 3  
Old 09-16-2010
But I need to use different logs everytime eg: timelog.log other than runningLog.log . So what should be in that case. So the Log file should be defined by the user.
# 4  
Old 09-16-2010
Ok! You can use something like:
Code:
echo "Please, enter the path and log file: "
read logFile

if [ ! -f "${logFile}" -o ! -r "${logFile}" ]
then
	echo "Invalid log file. It does not exist or is not readable."
	exit 1
fi

searchStrFile="SearchStrings.txt"
while read mLine
do
	egrep ''"${mLine}"'' "${logFile}"
done < "${searchStrFile}"

# 5  
Old 09-17-2010
But i have log file in this type.

logFile1
logFile2
logFile3
logFile4
logFile5

But above syntax is only for one file at a time, but the string should be searched in all the logs simultaneously

Do i need to enter the range like this.

Code:
echo "Please, enter the path and log file: " read logFile[1-5]

 if [ ! -f "${logFile[1-5]}" -o ! -r "${logFile[1-5]}" ] then 	echo "Invalid log file. It does not exist or is not readable." 	exit 1 fi  searchStrFile="SearchStrings.txt" while read mLine do 	egrep ''"${mLine}"'' "${logFile}" done < "${searchStrFile}".

# 6  
Old 09-17-2010
can you tell me if the log files you want to search in the same directory....
you can do something like this :- -
Code:
searchStrFile="SearchStrings.txt"
for file in `ls *`
do
echo "searching for the search pattern in the file $file"
while read mLine
do
echo "Searching for the line :-- $mLine"
egrep ''"${mLine}"'' "${file}"
done < "${searchStrFile}"
done

# 7  
Old 09-17-2010
The previous syntax works fine for me , but my only concern is it should search in all the log files whose naming convention is same except the extension. But this files are under same directory.
Quote:

# cd ${HOME}/logs/production
# ls -ltr
# queryinfoservice_Log4
queryinfoservice_Log2
queryinfoservice_Log5
queryinfoservice_Log1
queryinfoservice_Log3
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching exception keyword in all logs in last 5 minutes

Hello Folks , I am a new bie to the world of unix , what i am planning to do is the I have the location in server to which i am access through the putty and the location is /mt/ttlog/avccomn/logs/201901/19 and at this location the files are listed as show startjmsnode1.sh_03.out... (7 Replies)
Discussion started by: punpun26262626
7 Replies

2. Red Hat

Collecting logs by running command

Hi, i am a general user of linux but we work mostly on windows next i am moving full time on linux. here is my question: We have product which consist or several subsystem each subsystem has one module to create logs file dump. and i am going to write that support dump tool. we need to... (3 Replies)
Discussion started by: ajayyadavmca
3 Replies

3. Shell Programming and Scripting

To find latest set of logs among new and old

Hi All I am writing a script which will select the latest logs (which are generated every night via a script) among old one and new. Script generates set of 3 logs each time it runs. Example : log-WedJun082011_bkt1.log log-WedJun082011_bkt2.log log-WedJun082011_bkt3.log I have... (1 Reply)
Discussion started by: ratneshnagori
1 Replies

4. Shell Programming and Scripting

searching the required string and appending string to it.

Hi all, I have some data in the form of adc|nvhs|nahssn|njadnk|nkfds in the above data i need to write a script so thet it will append "|||" to the third occurnace in the string ..... the outout should look like adc|nvhs|nahssn||||njadnk|nkfds Thanks, Firestar. (6 Replies)
Discussion started by: firestar
6 Replies

5. Shell Programming and Scripting

Searching String from set of similar File pattern from the Dir

Guys, Here is the script that searches string from the set of similar files from the log directory, All the file patterns are defined as input file, from where the script should map to those files in the LOG_DIR and should start searching the strings from all those similar files. ... (1 Reply)
Discussion started by: raghunsi
1 Replies

6. UNIX for Advanced & Expert Users

How to find one partucular user logs when there are lots of users running on it

On my application there are lots of users are doing there work or tasks? ...In my SSH or in 'Putty' i am observing logs? Hot to observe one particular 'user' logs.. even through there are lots of users working on it? For EX: i am log in with use rid:nikhil@in.com. another one log in with... (4 Replies)
Discussion started by: ksr.test
4 Replies

7. Shell Programming and Scripting

Searching *.gz logs

I have been trying to search for a string from close to 200 *.gz file, But i get a error. Can someone suggest a bulletproof solution Please. zgrep 20/Aug/2008:13:50:23 request.log.*.gz -bash: /usr/bin/zgrep: /bin/sh: bad interpreter: Argument list too long also zgrep 20/Aug/2008:13:50:23... (9 Replies)
Discussion started by: openspark
9 Replies

8. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

9. UNIX for Dummies Questions & Answers

Process launched by user who logs out, continue running ?

Lets say a user starts a process (either a shell script or a Perl script) and before that process finishes, he logs out (either intentionaly or network problems or ...), does the process continu running ? Default shell is Korn. This is because at my job (being trained), there are tasks to run... (2 Replies)
Discussion started by: Browser_ice
2 Replies
Login or Register to Ask a Question