![]() |
|
|
google unix.com
|
|||||||
| Forums | Casino | Register | Forum Rules | Links | Albums | FAQ | Members List | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| tail -f | wannalearn | Shell Programming and Scripting | 4 | 04-10-2007 05:22 PM |
| Tail?? | qfwfq | Shell Programming and Scripting | 7 | 06-19-2006 01:15 AM |
| tail command.. | amon | Shell Programming and Scripting | 2 | 06-02-2006 04:36 AM |
| Help on scripting using tail | jisc | Shell Programming and Scripting | 4 | 05-19-2006 03:15 AM |
| how to sed with tail | redlotus72 | UNIX for Dummies Questions & Answers | 1 | 08-30-2005 05:27 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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. |
|
||||
|
Try this:
Code:
(tail -f /var/log/messages & ) | grep -i login This will just dump out to your screen until you hit something like ctrl+c. If you want something more elaborate, you could sent the tail output to a different fd, and have grep read in from that fd. Good luck! |
|
||||
|
Oh heck, why not - here's a slightly improved design. Run it in the background, and it will write the user defined above when it sees the exact phrase (also defined above).
It's not the pertiest, and probably not the fastest if the logs grows very quickly, but it works, and it's be easy to modify to mail, page, whatever... Just be careful that it doesn't flood you out if it finds the same message hundreds of times... Code:
#! /bin/ksh
search_word="search terms"
write_user=user_id
tail -n1 -f /path/to/log |&
while read -p output_line; do
[[ $output_line == *"$search_word"* ]] && {
print "$output_line" | write $write_user
}
done
|
||||
| Google The UNIX and Linux Forums |
![]() |
| Bookmarks |
| Tags |
| None |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|