GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Unix Help - Tail | Grep (https://gfy.com/showthread.php?t=238915)

Dusen 02-18-2004 07:04 PM

Unix Help - Tail | Grep
 
I'm trying to grep a tail -f out to a file.

But it doesn't seem to be working.

I am doing:

tail -f file | grep 'term' > file.txt

No output to file.

Anyone see what is wrong? Any ideas how to do this?

Veiga 02-18-2004 07:09 PM

That's correct, and I just tried and it works with me.

Is the file created but empty?

Dusen 02-18-2004 07:12 PM

Yes, that is what is happening.

Dusen 02-19-2004 06:44 AM

Anyone else help? I'm stuck.

I've scripted something up in perl but when the file gets truncated the perl script stops outputting to file.

com 02-19-2004 06:49 AM

looks fine to me, post your code

Dusen 02-19-2004 07:17 AM

PHP Code:

#!/usr/bin/perl

while (1) {
open LOG'access_log' || die "no can open file: $!";

seek(LOG,0,2);
for(;;) {
headerloop: while(<LOG>)
{
        
chomp;
        if (/.*(
texttofilter).*/)
        {
        
open YOURLOG'>> /home/me/outputfile' || die "can not write to file";
        print 
YOURLOG "$_","\n";
        }

}
sleep(1);
seek(LOG,0,1);
close YOURLOG;
}


Thanks :)

The grep option works without sending to file AND sending to file works without the grep there. It seems that soemthing is messed up.

Dusen 02-19-2004 06:11 PM

Bump?

com 02-19-2004 06:16 PM

hrm, perhaps you might try using 2&>/path/to/file

edit I havent touched perl in ages but what you've got there looks fine to me.

com 02-19-2004 06:19 PM

im sure im probably mistaken but shouldn't

>> /home/me/outputfile

be

> /home/me/outputfile

or at least have a statement to use concatonate or append depending on weather or not the file exists. *shrug*

Dusen 02-19-2004 06:22 PM

Hrmm, well depending on what I want to do, >> is just because I don't want to kill what is there now. Appending is much better for me.


I don't even need to use that script, I just need to tail -f a logfile and grep the output to another file. That's it.

I'm lost.

Dusen 02-20-2004 07:59 AM

A Final Bump

Alky 02-20-2004 08:04 AM

hate to ask a stupid question, but is there anything in the file your trying to tail?

some_idiot 02-20-2004 08:30 AM

It's the way that grep dumps the data pipe into standard out.

Give who | sort >> user.txt a try and I bet it works for you.

You're going to need to write a quick hack in perl to open a file
and then dump all standard input to it. Stick that in place of
the >> yourfile in your pipe chain. tail | grep | hack.pl


...or spend all day pulling your hair out searching for an answer
you probably won't find. :)

extreme 02-20-2004 08:34 AM

output buffering .. need to reach a certain amount of lines before the last pipe gets it.

extreme 02-20-2004 08:54 AM

and ...

tail -f file | awk '/term/ { print; fflush() }' > file.txt

.. solves it.

Dusen 02-20-2004 10:04 AM

Quote:

Originally posted by extreme
and ...

tail -f file | awk '/term/ { print; fflush() }' > file.txt

.. solves it.

Outstanding, it sure does.

Thanks a BUNCH, I really appreciate it.

Thanks to everyone who helped in this thread, I knew there were some fellow nix dorks lurking around here and I wasn't alone.

J


All times are GMT -7. The time now is 07:39 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123