Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to run a server that writes to $log (a txt file) and then find all the text in the logfile that starts with [1] and put it in another file. Here's my attempt. tee -a $log works along with everything else. The grep command doesn't though.

run="tail -n0 -f -s 0.01 $cmds | (while true; do $tron --userconfigdir $userconfigdir --userdatadir $userdatadir --vardir $var; done) | tee -a $log | grep '^\[1\]' > ${var}logs/chatlogs.log"

What can be done to copy all the text from tee -a $log starting with [1] to another file?

share|improve this question
    
What's the problem with grep ? do you get an error ? No output in ${var}logs/chatlogs.log ? No output in ${var}logs/chatlogs.log even though you've thoroughly verified there should be somewhere there (by running the grep on $log independently, for example) ? –  huitseeker Jul 31 '11 at 9:54
    
Sorry I didn't clarify. There is no output to chatlogs.log –  Kevin Duke Jul 31 '11 at 10:30
    
I don't believe that the problem is with the grep, but before it. If you remove the tee -a $log does it work? probably not –  hmontoliu Aug 1 '11 at 15:47

2 Answers 2

up vote 1 down vote accepted

It is normally fine to do this:

tail -f /var/log/mylog | egrep '^<txttomatch>' | tee /tmp/watchlog

Naturally, you only need tee if you wish to have console output as well as copying to file. If you are starting and stopping this process you may want to pass the -a switch to tee.

share|improve this answer
    
would txttomatch be in <> or without –  Kevin Duke Jul 31 '11 at 10:42
    
I used <txttomatch> to be a placeholder. So if you wanted lines starting jonny or Jonny you could egrep -i "^jonny". The ^ anchors the pattern to the start of the line. –  rorycl Jul 31 '11 at 12:05

What did you get when running it?

Try the alternative:

... tee -a $log >(grep '^\[1\]' > ${var}logs/chatlogs.log)
share|improve this answer
    
no luck, still a blank file –  Kevin Duke Jul 31 '11 at 10:42
    
Are you sure the output including some lines beginning with [1]: grep '^\[1\]' $log? –  quanta Jul 31 '11 at 10:47
    
Yes for example, this is the file $log is being tee'd too: pastebin.com/NaubAKqu –  Kevin Duke Jul 31 '11 at 10:54
    
Don't know why it didn't work with you. Try again with: tee >(grep '^\[1\]' > ${var}logs/chatlogs.log) >> $log –  quanta Jul 31 '11 at 11:16
    
that didn't work either :( –  Kevin Duke Jul 31 '11 at 19:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.