0

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?

dukevin
  • 1,630
  • 3
  • 18
  • 25
  • 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) ? – Francois G Jul 31 '11 at 09:54
  • Sorry I didn't clarify. There is no output to chatlogs.log – dukevin 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 01 '11 at 15:47

2 Answers2

1

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.

rorycl
  • 848
  • 1
  • 6
  • 10
  • would txttomatch be in `<>` or without – dukevin Jul 31 '11 at 10:42
  • I used 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
0

What did you get when running it?

Try the alternative:

... tee -a $log >(grep '^\[1\]' > ${var}logs/chatlogs.log)
quanta
  • 51,413
  • 19
  • 159
  • 217