Bash: wait for process to exit while tailing log file
In a bash script, I'm waiting on a child process's pid using wait. That child process is writing to a log file. Is there a way in the bash script to tail that log file to std out while at the same time waiting on the process to complete?
Use the tail command to follow the file while you wait for the command to finish.
command & cmdpid=$! tail -f -n +0 logfile & wait $cmdpid kill $!
This is in spirit similar to William's solution, but with one important difference: it will correctly print the log file if it takes longer for command to finish than it does for cat to print the file (quite likely, as cat is very fast). The -n +0 option tells tail to print the whole file before it starts following updates.