I have a process which starts and outputs to a log file. The script which starts it launches it in a GNU
screen and then follows the log with
The process will immediately begin writing to the log file and it's useful to be able to watch it start in this way as to spot any configuration errors and then drop back to the prompt with
ctrl-c. I am aware that this only stops the
tail does not terminate the process which is logging; this is desired.
What I want to do is start a second watchdog process from the shell script which is meant to perform an action only after the process which is running in the
screen has finished initializing; this occurs only AFTER all of the startup log output.
If I loop in my startup script and wait for the
screen process to initialize so that it can perform its action, then I lose out on the real-time
tail output. If I instead try to monitor the log and output its contents as I wait in my loop, then the user cannot
ctrl-c out of the script early without breaking the loop which is waiting for the initialization to complete.
To support both the watchdog and the
tail -f of the log file I can instead launch a job and then
disown it to guarantee than a logout won't kill it.
This is a lot of information for a simple question but I wanted to include all of the details related to my use-case to provide clarification in-case there is a better alternative.
Also of note, I could start another
screen but I don't need to interact with it and
disown seems to be a simpler alternative.
I'm also aware that I need to redirect output as necessary to prevent output to the parent shell.
Example code, tested and performs correctly when starting from a script and then logging out and back in:
#!/bin/bash ( sleep 10s; echo 1 > b ) & disown