I have a simple Bash-script that spend more than 99 % of its time on executing a Python application (the script is just a wrapper that feeds this Python script files in a for-loop and renames the output files). I have the same problem as described here and have looked at the answers but don't understand how to use them in my context.
I think I need to apply the principles in the answers to that question inside my script, on the line that executes the Python script, but how?
My script as pseudo-code:
for file in "$directory"; do
pythonscript "$file" >> "log.txt"; then
done
I want to flush the pythonscript-line every minute, every line of output it produces or similar, it doesn't matter that much (typically execution takes several hours, I just want to be able to track the output "reasonable" frequently).
/homedir/MyScriptthat you want to run unbuffered you should call is asstdbuf -oL /homedir/MyScriptinstead. Your script ispythonscript "$file"so call it asstdbuf -oL pythonscript "$file"instead. See gnu.org/software/coreutils/manual/html_node/… for more info onstdbuf.for file in "$directory"; do whatever; done >log.txtinstead offor file in "$directory"; do whatever >> log.txt; doneso you only open the output file once, andfor file in "$directory"is confusing terminology at best or simply a bug, depending on what it's meant to do.stdbuf(despite installingGNU core utilsfrom MacPorts).