Searching *.gz logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching *.gz logs
# 1  
Old 08-20-2008
Data 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 request.log*
-bash: /usr/bin/zgrep: /bin/sh: bad interpreter: Argument list too long


Thanks
# 2  
Old 08-20-2008
Woah, do you keep that many rotated log generations?
You run into this kind of problem when the shell's globbing would expand to more chars than what your shell's max arg length is.
But this, at least on this Linux box of mine here, is quite a few chars anyway, viz.
Quote:
$ getconf ARG_MAX
131072
If you still want to keep that many files then you would have to refrain from globbing
and use something like this
Quote:
$ ls | grep \\.gz\$ | xargs zgrep 20/Aug/2008:13:50:23
# 3  
Old 08-20-2008
Try this:

for F in `ls ./request.log.*.gz`; do zgrep 20/Aug/2008:13:50:23 $F; done

or even

ls request.log.*.gz |xargs "zgrep 20/Aug/2008:13:50:23"
# 4  
Old 08-21-2008
zgrep 'IN0800' eodlog.*.gz
i have 1000 of eodlog.*.gz
but this is not giving any errors..
# 5  
Old 08-21-2008
Then your kernel's ARG_MAX is bigger.
# 6  
Old 08-21-2008
i have encountered similar problems on servers keeping log files for 3 or 4 years
a new file is cerated evry 5 mins, so you can guess how many did i had to manage...

the proble is the expansion ( the * )
"ls *" is not the same as "ls"
ls * will be captuerd by the shell, and the * will replaced by the list of files in the current directory, separated by a whitespace.
when executing "ls" it will be ls the one to get the list.
keeping that in mind is all you need to work over that folder, but be aware that you are going to work mostly blind.

a few tips would be.
create a listing of the folder, soy ou dont have to re-list evrything all the time (my listing took more than 5 mins and made the server crawl)
ls > list-of-files
then, use other tools over that textfile, like grep or awk, ect

also, when you feel you are reado to work on the files, use a while, and read from that file
Code:
while read line
do
    echo "the var line has a line of the file, $line"
done  < list-of-files

and expect alot of cpu usage, so if that server is actually doing some other stuff, then try to coordinate some downtime or window
you are gona make the server be slow, and other prioceses in the server are ging to make your work slower
# 7  
Old 08-21-2008
Thanks for the replies !

Unfortunately none of them seem to work

1.ls | grep \\.gz\$ | xargs zgrep 20/Aug/2008:13:50:23

Takes for ever.

2.zgrep 20/Aug/2008:13:50:23 *
-bash: /usr/bin/zgrep: /bin/sh: bad interpreter: Argument list too long

Please provide any inputs its quite critical !

I am searching a string FROM close to 200 .gz files each in the range of 2 - 3 MB.


Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

3. UNIX Desktop Questions & Answers

regarding logs

Hi , I am running an application on my windows and it logs are generated at /var/logs and for this i have to go this location and then do tail -f , Is there any command you can advise me so that when I execute this command at this location that logs get displayed fully and as the application... (3 Replies)
Discussion started by: KAREENA18
3 Replies

4. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

5. Shell Programming and Scripting

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... (14 Replies)
Discussion started by: raghunsi
14 Replies

6. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

7. UNIX for Advanced & Expert Users

logs

Hy, I have a question I have a directory in a unix server, Some of my files have a diffrent access time, from the time i accessed them last, I think some one has copied it,it's not an important file,but none the less,it is my file,It mistakenly had a 777 permission( yes ,I know it is a noob's... (1 Reply)
Discussion started by: lordmod
1 Replies

8. Shell Programming and Scripting

Logs

Hey Guys, i am new into shell programming and i have to do one script which have to record all the commands entered by a specific user. Example of that, i have a system running on unix, several users are using this system, i have to create like a databse which will record every user entered that... (5 Replies)
Discussion started by: charbel
5 Replies

9. UNIX for Dummies Questions & Answers

logs

can i include this command into my crontab file > /var/adm/wtmp to clear the contents on a regular basis ? what about file permissions ? (6 Replies)
Discussion started by: cubicle^dweller
6 Replies

10. UNIX Desktop Questions & Answers

Logs

hi My name is Juan I dont can clear wtmp and similiar files how i do it? thanks (4 Replies)
Discussion started by: jtapia
4 Replies
Login or Register to Ask a Question