grepping an open file

grepping an open file

Post by Sash » Sat, 01 Oct 2005 05:52:58



Hi, I'm grepping for a pattern (GNU/Linux, BASH 2.05) in a log file
that's open by a process. When I run grep on this file, grep doesn't
exit and I suspect it's because the file is open by a process and grep
is waiting for further input.
Is my assumption right? How do I make grep not wait for more input? The
man page didn't mention anything about grepping files open under other
processes.
TIA,
Sashi
 
 
 

grepping an open file

Post by Stephane CHAZELA » Sat, 01 Oct 2005 06:05:12


2005-09-29, 13:52(-07), Sashi:

Quote:> Hi, I'm grepping for a pattern (GNU/Linux, BASH 2.05) in a log file
> that's open by a process. When I run grep on this file, grep doesn't
> exit and I suspect it's because the file is open by a process and grep
> is waiting for further input.
> Is my assumption right?

No, unless that file is a pipe (ls -l output would start with a
"p"). But in that case you shouldn't grep it; if it's a FIFO,
the program writing to it probably expects some specific program
to read the other end of the pipe, and you shouldn't let grep
interfer with that.

If it's not a fifo, try to find out what grep is doing.

Running

strace -p $(pidof grep)

when grep is stuck may give some information.

--
Stphane

 
 
 

grepping an open file

Post by Ed Morto » Sat, 01 Oct 2005 06:09:05



> Hi, I'm grepping for a pattern (GNU/Linux, BASH 2.05) in a log file
> that's open by a process. When I run grep on this file, grep doesn't
> exit and I suspect it's because the file is open by a process and grep
> is waiting for further input.
> Is my assumption right? How do I make grep not wait for more input? The
> man page didn't mention anything about grepping files open under other
> processes.

You're probably wrong. Check that the file exists, check that you're
quoting your variables properly, and if that doesn't fix it, post back
here and show the actual command you used.

        Ed.

 
 
 

grepping an open file

Post by Sash » Sat, 01 Oct 2005 06:29:39




> > Hi, I'm grepping for a pattern (GNU/Linux, BASH 2.05) in a log file
> > that's open by a process. When I run grep on this file, grep doesn't
> > exit and I suspect it's because the file is open by a process and grep
> > is waiting for further input.
> > Is my assumption right? How do I make grep not wait for more input? The
> > man page didn't mention anything about grepping files open under other
> > processes.

> You're probably wrong. Check that the file exists, check that you're
> quoting your variables properly, and if that doesn't fix it, post back
> here and show the actual command you used.

>    Ed.

Ed, Stephane, it was my mistake. The log files were MUCH bigger than I
estimated and grep was running its course and I got impatient! I'm all
red faced!
Thanks for your help, though!
Sashi
 
 
 

1. grep attempts to grep in non-ascii files

This is an area where I with that the "file" command were a bit more
robust. It does a good job of identifying the type of file it is examining,
but it doesn't provide it's feedback in a machine-friendly format. What
would be nice is if there were an option that would output a two-digit
value for the type of file that is being examined - that a shell script
could examine the value and decide whether certain operations should be
performed or not.

2. Need Graphics Driver for SBT Velocity 128 AGP card for SCO 5.04

3. OpenWin Filemgr: 'cannot open file: too many files open' ?

4. __argz_count ... What library is this in?

5. Help: What controls number of files a user can open (file open command)?

6. Q: Linux, XFree2.1, XF86_Mono, Sigma LaserView, black screen

7. Open File Manager (open file backup) for Linux?

8. NET-2 configuration files, new hostname failure

9. grep sTerm * | grep -v grep ???

10. tail | grep | grep | grep

11. How do I grep a file and move found files to a directory?

12. Parse file names for string and then grep these files ??

13. File open or not open ???