4

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?

Vinz
  • 2,150
  • 14
  • 16
gsf
  • 183
  • 6

5 Answers5

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
  • 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 03 '15 at 20:51
  • tail the log files when you get curious? – Jeff Schaller Nov 03 '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 04 '15 at 02:26
2

actually, I found what I need to do:

parallel --j 2 -- "sh script1" "sh script2" &
PID=$!
tail --pid=$PID -f log1 log2
gsf
  • 183
  • 6
  • 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 '20 at 17:23
0

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

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
David King
  • 3,147
  • 9
  • 23
0

I would use Multitail or tmux.

Bob
  • 126
  • 4
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.

cas
  • 78,579