2

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 '15 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 '17 at 13:07
2

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 '15 at 20:51
  • tail the log files when you get curious? – Jeff Schaller Nov 3 '15 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 '15 at 2:26
1

actually, I found what I need to do:

parallel --j 2 -- "sh script1" "sh script2" &
PID=$!
tail --pid=$PID -f log1 log2
0

I would use Multitail or tmux.

  • 1
    How, and why would you? – roaima Nov 3 '15 at 23:17
0

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 '15 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 '15 at 20:05
  • 2
    This is a question, not an answer. – Vinz Nov 3 '15 at 20:12
  • 5
    This is incredibly not a question; you guys have to stop flagging everything that ends in a question mark – Michael Mrozek Nov 3 '15 at 22:30
  • It might not be a question, but it is not answer of the question as well. – gsf Nov 4 '15 at 3:05
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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