I am writing a bash script to perform regular server maintenance. For this task, I am running a program that will take about 30 minutes to execute and will write to stdout every few minutes. I need the script to process these lines that the program writes in real time. I'm currently using a read-while loop to process each line like the following:
output=$($maintenance_command) while read -r line; do <processing logic> done <<< "$output"
and it does work properly, but it does not do any of the processing until the program exits. Is there any way to run this in the background and read the output as it is written?