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 05-25-2010, 02:36 PM   #1
Vhal
LQ Newbie
 
Registered: May 2010
Posts: 15

Rep: Reputation: 0
(e)grep and tee question


im trying to log output to a file and still view the output in terminal (using tee)

but, i also need to grep this, and still view the original output...

so...watch the output, and have it grep a string and save instances of that string to a text file...

heres a snippet of my perl script im doing this in..

exec ("telnet perry $host | tee /home/blah1/blah2/blah3/$station/$dir/$system.txt")

while this works fine as is, id like to have this sorted and save only the string i specify to the text file. but...i need to also see the original output.

make sense?
 
Old 05-25-2010, 02:55 PM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,021
Blog Entries: 1

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
One option is to log it all and grep it later. and/or tail -f in another term to do the other stuff. Not sure of a way to do a one liner. But curious. tee does let you put it back out to - (/dev/stdout), but that doesn't seem to split the outputs like you seem to need.
 
Old 05-25-2010, 03:29 PM   #3
Vhal
LQ Newbie
 
Registered: May 2010
Posts: 15

Original Poster
Rep: Reputation: 0
yeah its going to be a constant telnet session thats logging multiple reboots of a machine. im saving its output to a file, and with each reboot the file gets bigger. so instead of searching through all that text im trying to either have it save the lines im looking for, or have it save another file with those lines..
 
Old 05-25-2010, 08:38 PM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,021
Blog Entries: 1

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
You could always append a date/time stamp as part of the filename. That way it always starts a new file. And you can easily keep track of what happened and when. And sort and delete as needed. Or just ping the computer once a minute and log when ping fails. Assuming network, assuming ping sends a reply (firewall), and other things.
 
Old 05-26-2010, 11:23 AM   #5
Vhal
LQ Newbie
 
Registered: May 2010
Posts: 15

Original Poster
Rep: Reputation: 0
yeah iv done the date stamp thing. i just get fixed on an idea and wondering whether or not it can be done, which is the case here.. just seems simple but its proving not to be lol

i have tried tee'ing to seperate processes but it still isnt working. was thinking of trying a while loop but that seems like a bang-your-head approach.

youd think there would be a simple way to say "hey, show me the consistent output, but save only these lines to a text file"
 
Old 05-26-2010, 03:05 PM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,021
Blog Entries: 1

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
You might look at screen, perhaps it can help fork the processes.

in one xterm you could:
$ 0>logfile.txt
$ tail -f logfile.txt | grep -i "filter" > filteredlog.txt

and in the other you could
$ telnet perry $host | tee logfile.txt

With obvious limitations. tail needs to happen first. tail needs to be manually terminated when not relevant anymore. And the common file needs to match between processes.

Or maybe there's a grep option to output to multiple sources. stderr to screen(2) and stdout(1) to file. From stdin(0). Or something similar in tee. It does have - output, but I wasn't able to rig it to do two outputs. But I'm not that familiar with these apps.
 
Old 05-26-2010, 06:42 PM   #7
Vhal
LQ Newbie
 
Registered: May 2010
Posts: 15

Original Poster
Rep: Reputation: 0
well, i know with tee you can send it to seperate processes ... | tee >(process 1) >(process2) >(process3), but i have yet to achieve the desired results. i have tried doing a seperate process that does the grep filtering, but it doesnt quite work while the file is constantly being written to... maybe i need to post this in a scripting/programming forum lol. a lot of this is still new to me.
 
Old 05-27-2010, 06:46 AM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,021
Blog Entries: 1

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
Sounds like a plan.

I tried some of that > and - stuff, but tee was assuming only one path in all cases. Maybe there's a different version of tee or your/my distro compiled it funny.
 
  


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
grep question tekmann33 Linux - Newbie 1 08-11-2008 11:22 AM
question about grep new_2_unix Linux - Newbie 5 12-07-2007 04:45 PM
grep question tokernizer Programming 2 12-20-2005 08:02 AM
grep question djgerbavore Linux - Newbie 3 11-04-2004 10:53 AM
grep question djgerbavore Linux - Newbie 7 07-07-2004 07:11 AM


All times are GMT -5. The time now is 09:01 PM.

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