0

I have a bash script that executes for a very long time and produces some log information to the std output:

bash execute_stuff_for_a_long_time.sh

This bash script gets launched as a daemon using a double fork technique: ( &)

Now the challenge I have, is that I would like to launch this script from another script as I am doing, and log its output to a file in real time. While this seems easy, I am hitting the following problem: it looks like the logs do not get written before the script has finished executing, which may take a long time (or even forever). For example, if I launch the script through another script, which content is:

(bash execute_stuff_for_a_long_time.sh >> output.log &)

or

(bash execute_stuff_for_a_long_time.sh | tee -a output.log &)

It seems that I only get data written to output.log once the execute_stuff_for_a_long_time.sh script has returned (in my case, crashed).

So my question is: is there a way to launch a script from another script as a daemon using double fork, in such a way that the output gets appended to a file in real time?

Zorglub29
  • 5,541
  • 4
  • 18
  • 33

0 Answers0