shelltail

shell: how to make tail of a file running in background


I want to run a few tasks in shell.

  1. tail a file into a new file: for example: tail -f debug|tee -a test.log
  2. at the same time, run other tasks.

My question is: how to make the command tail -f debug|tee -a test.log run in background, so that I can run other tasks then in shell script?


Solution

  • You don't need tee at all for this, just use the shell's built-in append operator:

    tail -f debug >> test.log &
    

    The trailing & works as normal in the shell. You only need tee to send the output to a file as well as standard out, which if you have it in the background probably isn't what you want.