I have

parallel --j 2 -- "sh script1" "sh script2"

where script1 and script2 log in files log1 and log2

I would like to change this to:

parallel --j 3 -- "sh script1" "sh script2" "tail -f log1 log2"

The reason to use tail is when I allow the two scripts to output on the screen at the same time - the output becomes a mess and I lose the cursor etc issues - I need to restart the terminal almost after every execution.

The problem though is that now this will go forever and I would like tail to exit when script1 and script2 are done. How I can do that?

  • Could you edit the Q to include the OS we're running under? (as a tag or as text, or both)
    – Jeff Schaller
    Nov 4, 2015 at 1:08
  • If any of the existing answers solves your problem, please consider accepting it via the checkmark. Thank you!
    – Jeff Schaller
    Apr 23, 2017 at 13:07
  • To tail log until process ends, but watch process output at the same time, try this: stackoverflow.com/a/60134868/658497
    – Noam Manos
    Feb 9, 2020 at 8:48

5 Answers 5


This may also not be what you want, but how about:

parallel --j 2 -- "sh script1" "sh script2"; tail log1 log2

Once both jobs are done, you get the non-waiting tail of both log files.

  • scripts are really long term and I would like to be able to look at from time to time and see how it is going
    – gsf
    Nov 3, 2015 at 20:51
  • tail the log files when you get curious?
    – Jeff Schaller
    Nov 3, 2015 at 21:21
  • that exactly to point of the question - how to make it part of the script, because I am sure that I will get curious at several points, so I would like the script to do it for me
    – gsf
    Nov 4, 2015 at 2:26

actually, I found what I need to do:

parallel --j 2 -- "sh script1" "sh script2" &
tail --pid=$PID -f log1 log2
  • Be careful of tail's --pid=$PID, it's painfully slow in my experience (adds a second or so on exit). An exit trap is faster, but not as robust imo.
    – jozxyqk
    Oct 13, 2020 at 17:23

I would use Multitail or tmux.

  • 3
    How, and why would you? Nov 3, 2015 at 23:17

Hit Ctrl+C once the scripts are done to kill the tail manually.

  • I can, but this will stop the execution of the rest of the script
    – gsf
    Nov 3, 2015 at 20:03
  • actually if I am careful to do it once it won't, but it still going to wait for me before proceed further, which is not what I want
    – gsf
    Nov 3, 2015 at 20:05
  • 2
    This is a question, not an answer.
    – Vinz
    Nov 3, 2015 at 20:12
  • 5
    This is incredibly not a question; you guys have to stop flagging everything that ends in a question mark Nov 3, 2015 at 22:30
  • It might not be a question, but it is not answer of the question as well.
    – gsf
    Nov 4, 2015 at 3:05

parallel --j 2 -- "sh script1" "sh script2" & tail -f log1 log2

This runs parallel ... in the background and then runs tail ....

Pressing Ctrl-C on the tail won't effect the parallel jobs.

If you need to bring the parallel to the foreground, kill the tail and type fg. To send it to the background again (e.g. so you can run tail once more), press Ctrl-Z and type bg. Or you can kill it with kill %%

See your shell documentation for more details. e.g. if you are using bash, run man bash and search for (all-caps) JOB CONTROL.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .