Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

tail

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?

like image 510
zhaojing Avatar asked Jul 15 '11 03:07

zhaojing


2 Answers

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.

like image 110
evil otto Avatar answered Sep 22 '22 18:09

evil otto


Normally you just use an ampersand after the command if you want to background something.

tail -f debug|tee -a test.log &

Then you can bring it back to the foreground later by typing fg. Did this answer your question or have I missed what you were asking?

like image 44
Jason Striegel Avatar answered Sep 19 '22 18:09

Jason Striegel