Date: Thu, 4 Jan 2007 13:09:58 -0800 From: Matthew Hudson <fbsd@synoptic.org> To: freebsd-hackers@freebsd.org Subject: Re: Reading in real time from a file without pipes Message-ID: <20070104210958.GB46929@gort.synoptic.org>
next in thread | raw e-mail | index | archive | help
Mon Dec 11 09:08:37 PST 2006 c0re dumped wrote: > I wonder if is possible to read data from a > certain file without using a pipe. > > Let me explain: > > I have a process already writing messages to > a logfile. I want to read all written data > (without neither stop nor interfere normal > log process) from another process in real > time. > > How can I achieve it ? When on the command line, I do this using the program 'socat' (net/socat in ports). I.e. socat FILE:/var/log/messages,ignoreeof - This gives me the same sort of behavior as 'tail -f' except that it reads the entire file in first. I also use this when I'm say scp'ing over a really large tarball of text files and want to start looking at the files as they're coming in: * bigdir.tgz is a big tarball being scp'd over, 3 hours remaining * socat FILE:bigdir.tgz,ignoreeof - | gzip -dc | tar xf - & and just like that I now have bigdir.tgz being expanded in realtime without having to do anything that may have interfered with the scp (such as using ssh to run 'tee' on the remote host and do it that way. I know this isn't what you were asking since but I wanted to take the quick opportunity to brag about socat since I think it's the most powerful and useful utility that nobody seems to have heard about. More in line to what you're asking, I think the magic you're looking for is hinted to by the name of the option that socat uses, i.e. 'ignoreeof'. I'd surmise that all that socat and 'tail -f' are doing are reading until the end of a file and when they get a EOF, they simply wait a few milliseconds and try again. cheers -- Matthew Hudson
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070104210958.GB46929>