The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. Shell Script Page.


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tail -f wannalearn Shell Programming and Scripting 4 04-10-2007 02:22 PM
Tail?? qfwfq Shell Programming and Scripting 7 06-18-2006 10:15 PM
tail command.. amon Shell Programming and Scripting 2 06-02-2006 01:36 AM
Help on scripting using tail jisc Shell Programming and Scripting 4 05-19-2006 12:15 AM
how to sed with tail redlotus72 UNIX for Dummies Questions & Answers 1 08-30-2005 02:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-2002
Registered User
 

Join Date: Sep 2001
Location: D.C.
Posts: 48
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Question using tail -f

Working in HP-UX 10.20. I eventually want to write a bourne shell script to handle the following problem, but for now I am just toying with it at the command line.

Here's what I am basically trying to do:

tail -f log_X | grep n > log_Y

I am doing a tail -f on log_X . Once it sees "n", I would like for it to grep it, then put it into log_Y. It ain't making it to log_Y.

I have been manually adding "n" to log_X, and the tail command is definitely seeing it, but it fails to pass it to log_Y.

Why? Is it because the command is trying to "complete" the tail -f before it executes the > (redirect) to log_Y??

Is there a better way to appraoch this?

TYIA
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-23-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
try using

tail -f log_X | grep n >> log_Y

I'm not sure this would work...

I can add that the commands on either side of a pipe "|" are started and executed synchronously... and we know that any command like grep will finish only if it sees an EOF, which "tail -f" will not give as it is in an infinite loop looking for newly appended lines...

so...

tail -f log_X | grep n

should be working fine and giving "new" lines having "n" to stdout as and when they append to log_x...

It may be a problem with redirection, so use redirection in append mode >> and let us know!!

Cheers!
Vishnu.
Reply With Quote
  #3 (permalink)  
Old 10-23-2002
Registered User
 

Join Date: Sep 2001
Location: D.C.
Posts: 48
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Vishnu:

I tried using tail -f log_X | grep n >> log_Y yesterday...it DID NOT work. I also tried a tail -f log_X | grep n >! log_Y. No go.

The reason I am using tail -f is because I want this to be a "real-time monitor". Once "n" appears, I need it to notify me.

Any other ideas?

TYIA
Reply With Quote
  #4 (permalink)  
Old 10-23-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
see these posts.. it seems that piping "tail -f" works with some OSes and does not work with some...

http://www.computing.net/solaris/www...orum/1734.html

http://www.zsh.org/mla/users/1999/msg00360.html

you did not tell whether...

tail -f log_X | grep n

worked on your system.. i.e., you can see the stuff on your terminal..

Cheers!
Vishnu.
Reply With Quote
  #5 (permalink)  
Old 10-23-2002
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
daemon process gives real time

It seems that you would be better served to create a daemon to control this process.

You could tailor it to notify you when the string you want appears and email or beep you. You should have a template of one on your system or you can copy from a simple one in a directory similar to /sbin/init.d/template.

cp template myscript

You will need to add a kill and start link in your rc directories for it to startup a boot time.

ln -s myscript /sbin/rc3.d/S400myscript
ln -s myscript /sbin/rc1.d/K400myscript


Hope this helps!
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 02:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102