4 ms·
> The script should be decently self-explanatory [...] Please note that this is all single-threaded, which I don’t recommend - with nohup and the like, you can
by wodenokoto 5y ago
> The script should be decently self-explanatory [...] Please note that this is all single-threaded, which I don’t recommend - with nohup and the like, you can trivially parallelize this.
How do you parallelize a loop in bash without getting all the echo's intertwined and jumbled together?
- karlding 5y agoIn general, you can partition the loop to delegate to "workers" and have each instance pipe the output to different files, each corresponding to an output stream. This avoids the need for mutual exclusion around your output streams. If you need to aggregate logs then run some log aggregator.
- otter-in-a-suit 5y agoMaybe not nohup itself, but I often do simple background tasks + a blocking `wait` statement in a loop, for instance here: https://github.com/chollinger93/debian-scripts/blob/master/util/create_random_files.sh#L30 https://github.com/chollinger93/debian-scripts/blob/master/u... If you don't use nohup, you can just pipe stdout and err to a different file descriptor for logs within said loop. Or, of course, script something in a language of your choice.