So, I've got a rather long and involved script intended to be used by people who aren't going to want to dig into anything that goes wrong.
Recently, during testing, the script froze inexplicably. Long story short, I executed a command in a subshell in order to be able to tee stdout and stderr to my log file:
(/path/to/script -i -ran 2>&1; ) | tee -a /path/to/mylogfile
The script was no longer in the process tree, no longer running, and seems to have exited completely because the file that it writes as its last action was there and not open. However, tee remained, obstinately. I killed tee, and the script proceeded merrily on its way. This is the first time this has happend, and I want to know if there's anything I can do to prevent it from happening again. Any ideas would be most appreciated.
#!/bin/bash -x
to figure out what's happens – Nativebornfile /path/to/mylogfile
to see (its pretty common to do this for logging so that a daemon can process any errors etc...) – Chelicerauberscript
— that contains in part the invocation of/path/to/script
andtee
. The script that was not in the process tree was/path/to/script
; when the orphanedtee
was killed, it was theuberscript
that went merrily on its way. – Schellensset -o pipefail
might be needed to tell tee to disconnect when the process being piped in exits. In my case, the process I'm piping into tee uses#!/bin/sh
for shebang, so I'm wondering if that's also part of the problem... Anyway, going to keep digging. Will post an answer if I find anything conclusive. – Webbed