LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2006, 02:50 PM   #1
Critcho
LQ Newbie
 
Registered: Feb 2006
Posts: 20

Rep: Reputation: 0
Tail - only show matched phrase


I am tailing a log file with

Code:
tail -f /var/log/messages -n 200
However, this file spews a whole lot of messages on my screen, and I am only interested in one - AT+CFUN=0.

I plan to have two windows - one with the specific watch and one with the complete tail. When the specific watch gets a hit, I can switch to the full tail and see what happened before the event, but without going blind watching the log files and trying to catch the event.

Guess I'm after a hybrid tail/grep... Is there such a beast?

Linux version is embedded into an Axis single board CPU:
BusyBox v0.60.5 (2005.09.26-02:02+0000) Built-in shell (ash)

Thanks,
Cheers,
Critcho.
 
Old 02-15-2006, 03:32 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
hi if you man grep i think option -B will give you what you need.
 
Old 02-15-2006, 03:33 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Have you looked at the swatch application?
 
Old 02-15-2006, 04:24 PM   #4
Critcho
LQ Newbie
 
Registered: Feb 2006
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks for the suggestions, looks like this version of Linux doesn't like either of those options:

Code:
[root@AxisProduct /var/log]29054# grep
BusyBox v0.60.5 (2005.09.26-02:02+0000) multi-call binary

Usage: grep [-ihHnqvs] PATTERN [FILEs...]

Search for PATTERN in each FILE or standard input.

Options:
        -H      prefix output lines with filename where match was found
        -h      suppress the prefixing filename on output
        -i      ignore case distinctions
        -l      list names of files that match
        -n      print line number with output lines
        -q      be quiet. Returns 0 if result was found, 1 otherwise
        -v      select non-matching lines
        -s      suppress file open/read error messages

[root@AxisProduct /var/log]29054#
[root@AxisProduct /var/log]29054# swatch
swatch: No such file or directory
[root@AxisProduct /var/log]29054#
I was hoping to find some way to combine the two commands (sorta like a pipe), but I guess that isn't possible.

Next step I guess is a small batch file to grep the file every 5 seconds....
 
Old 02-15-2006, 04:46 PM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Well, yes, you'd need to install swatch from, e.g., SourceForge, before you could use it.

You're using "BusyBox V0.6.50" for this? I thought BusyBox was primarily for use in embedded systems, where memory was really limited, and I wouldn't have thought that any windowing system would/could run with only BusyBox/
 
Old 02-15-2006, 04:48 PM   #6
Critcho
LQ Newbie
 
Registered: Feb 2006
Posts: 20

Original Poster
Rep: Reputation: 0
Yup, this is on a small platform on an embedded Single Board Computer. I'm watching the log via a telnet session from my PC. Installing software isn't really an option I guess.
 
Old 02-15-2006, 04:50 PM   #7
tuxrules
Senior Member
 
Registered: Jun 2004
Location: Chicago
Distribution: Slackware64 -current
Posts: 1,144

Rep: Reputation: 56
Quote:
Originally Posted by Critcho
Thanks for the suggestions, looks like this version of Linux doesn't like either of those options:

Code:
[root@AxisProduct /var/log]29054# grep
BusyBox v0.60.5 (2005.09.26-02:02+0000) multi-call binary

Usage: grep [-ihHnqvs] PATTERN [FILEs...]

Search for PATTERN in each FILE or standard input.

Options:
        -H      prefix output lines with filename where match was found
        -h      suppress the prefixing filename on output
        -i      ignore case distinctions
        -l      list names of files that match
        -n      print line number with output lines
        -q      be quiet. Returns 0 if result was found, 1 otherwise
        -v      select non-matching lines
        -s      suppress file open/read error messages

[root@AxisProduct /var/log]29054#
[root@AxisProduct /var/log]29054# swatch
swatch: No such file or directory
[root@AxisProduct /var/log]29054#
I was hoping to find some way to combine the two commands (sorta like a pipe), but I guess that isn't possible.

Next step I guess is a small batch file to grep the file every 5 seconds....
Would this not work?
Code:
tail -n /var/log/messages -n 200 | grep <what-ever>
Swatch is actually a software package you have to install. Look up at swatch.sourceforge.net --- Others already beat me on this one.

You can also use awk to cat a specific pattern you are looking for.

Tux,

Last edited by tuxrules; 02-15-2006 at 04:51 PM.
 
Old 02-15-2006, 04:57 PM   #8
Critcho
LQ Newbie
 
Registered: Feb 2006
Posts: 20

Original Poster
Rep: Reputation: 0
Working OK with a script, not the neatest output but it does the job...

Code:
while true
do
echo -
grep -n CFUN messages
done
Output is just "-" per line a few times a second, will show the line containing CFUN when it is written.

Guess that's the way it happens when you're a programmer - if it doesn't exist, make it yourself!
 
Old 02-15-2006, 06:32 PM   #9
Critcho
LQ Newbie
 
Registered: Feb 2006
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by tuxrules
Would this not work?
Code:
tail -f /var/log/messages -n 200 | grep <what-ever>
Tux,
Actually... yup - it works fine!!

Thanks Tux, easy when you know how!
 
Old 02-15-2006, 08:36 PM   #10
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Quote:
Originally Posted by Critcho
I was hoping to find some way to combine the two commands (sorta like a pipe), but I guess that isn't possible.
To combine commands with a pipe, use a pipe (|) between them...
 
Old 02-16-2006, 10:40 AM   #11
Critcho
LQ Newbie
 
Registered: Feb 2006
Posts: 20

Original Poster
Rep: Reputation: 0
Yeah, I knew about pipe, just wasn't sure if those two could be combined, because tail has a continual output, and grep is a one-shot command.....
 
Old 02-16-2006, 11:27 AM   #12
tuxrules
Senior Member
 
Registered: Jun 2004
Location: Chicago
Distribution: Slackware64 -current
Posts: 1,144

Rep: Reputation: 56
Quote:
Originally Posted by Critcho
Yeah, I knew about pipe, just wasn't sure if those two could be combined, because tail has a continual output, and grep is a one-shot command.....
AFAIK, tail command also gives you a snapshot of a file at the instance of running the command. It won't continuously tail the file with new output, even if the original file is being populated while you are tailing it. But I may be wrong.

Tux,
 
Old 02-16-2006, 12:19 PM   #13
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Ah, I see what you're saying. Take a look at the difference between "tail" and "tail -f".
 
Old 02-16-2006, 01:03 PM   #14
tuxrules
Senior Member
 
Registered: Jun 2004
Location: Chicago
Distribution: Slackware64 -current
Posts: 1,144

Rep: Reputation: 56
Quote:
Originally Posted by jrdioko
Ah, I see what you're saying. Take a look at the difference between "tail" and "tail -f".
Just goes to show how closely I should read the man pages....

Tux,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
window id, gnome-like desktop when show icons disabled (KDE, 2005 LE) + root-tail Emmanuel_uk Mandriva 1 11-16-2005 01:27 PM
MD Sums not matched... jcollard Linux - Software 4 02-10-2005 05:09 PM
Kernel version not matched for VMware muneebs Linux - Software 1 02-01-2005 11:54 PM
how do I get root-tail to show up on startx? atheist Linux - Software 5 10-24-2004 01:39 AM
grep a phrase degraffenried13 Linux - General 1 04-04-2004 12:10 PM


All times are GMT -5. The time now is 06:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration