Unix Help - Tail | Grep

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dusen
    Confirmed User
    • Aug 2002
    • 2251

    #1

    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?
    Penis Pill Sponsor List and Reviews:
    http://www.pillsponsors.com
  • Veiga
    Confirmed User
    • Jun 2001
    • 157

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

    Is the file created but empty?
    Sell me your portuguese Traffic!
    Euro Luso

    Comment

    • Dusen
      Confirmed User
      • Aug 2002
      • 2251

      #3
      Yes, that is what is happening.
      Penis Pill Sponsor List and Reviews:
      http://www.pillsponsors.com

      Comment

      • Dusen
        Confirmed User
        • Aug 2002
        • 2251

        #4
        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.
        Penis Pill Sponsor List and Reviews:
        http://www.pillsponsors.com

        Comment

        • com
          Confirmed User
          • Aug 2003
          • 4541

          #5
          looks fine to me, post your code

          Real. Professional. Hosting.
          .:Expect Nothing Less:.
          320-078-843 :: www.realprohosting.com :: [email protected]

          Comment

          • Dusen
            Confirmed User
            • Aug 2002
            • 2251

            #6
            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.
            Penis Pill Sponsor List and Reviews:
            http://www.pillsponsors.com

            Comment

            • Dusen
              Confirmed User
              • Aug 2002
              • 2251

              #7
              Bump?
              Penis Pill Sponsor List and Reviews:
              http://www.pillsponsors.com

              Comment

              • com
                Confirmed User
                • Aug 2003
                • 4541

                #8
                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.

                Real. Professional. Hosting.
                .:Expect Nothing Less:.
                320-078-843 :: www.realprohosting.com :: [email protected]

                Comment

                • com
                  Confirmed User
                  • Aug 2003
                  • 4541

                  #9
                  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*

                  Real. Professional. Hosting.
                  .:Expect Nothing Less:.
                  320-078-843 :: www.realprohosting.com :: [email protected]

                  Comment

                  • Dusen
                    Confirmed User
                    • Aug 2002
                    • 2251

                    #10
                    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.
                    Penis Pill Sponsor List and Reviews:
                    http://www.pillsponsors.com

                    Comment

                    • Dusen
                      Confirmed User
                      • Aug 2002
                      • 2251

                      #11
                      A Final Bump
                      Penis Pill Sponsor List and Reviews:
                      http://www.pillsponsors.com

                      Comment

                      • Alky
                        Confirmed User
                        • Apr 2002
                        • 5651

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

                        Comment

                        • some_idiot
                          Confirmed User
                          • May 2002
                          • 1511

                          #13
                          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.

                          This AVS pays my mortgage!

                          Comment

                          • extreme
                            Confirmed User
                            • Oct 2002
                            • 2120

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

                            Comment

                            • extreme
                              Confirmed User
                              • Oct 2002
                              • 2120

                              #15
                              and ...

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

                              .. solves it.

                              Comment

                              • Dusen
                                Confirmed User
                                • Aug 2002
                                • 2251

                                #16
                                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
                                Penis Pill Sponsor List and Reviews:
                                http://www.pillsponsors.com

                                Comment

                                Working...