2

I have a script that calls a number of other install scripts

./script1.sh 2>&1 | tee script1.log<br>
./script2.sh 2>&1 | tee script2.log<br>
./script3.sh 2>&1 | tee script3.log<br>

They all look ok till the last one which does a call to a custom init script. This init script runs the daemon as /usr/local/daemon &. i.e. puts it into the background.

Combine this with using tee and the main script hangs as the final tee never exits.

The init script is a .NET app running under mono so I've very little control over it. If I don't use tee then it all looks ok. Running the last command from the command line has the same effect.

If anyone can suggest a way of making the script exit cleanly I'd be grateful. For now I've moved the call to the init script out of script3 into the parent script and it works fine but of course it's not logged.

Cfinley
  • 1,435
  • 3
  • 14
  • 20
Terry
  • 51
  • 1
  • 4
  • Ran into this problem redirecting output from rust's cargo build tool, also found this thread on the topic: http://compgroups.net/comp.unix.aix/weird-tee-command-hang-korn-shell/1252821 so far I didn't see any good solutions besides working around the problem. – ideasman42 Dec 27 '16 at 04:33

2 Answers2

1

This may not be the best answer, but you can do tee script3.log & (with an ampersand in the end), so that the script can terminate without hanging. It does have the side effect of terminating the script before terminating script3.sh.

Valmiky Arquissandas
  • 1,855
  • 16
  • 23
0

Tee will not exit gracefully until the stdout of both the parent and child process gets closed. Try redirecting the stdout of the daemon

/usr/local/daemon > /dev/null 2>&1 &
Ashok Vairavan
  • 311
  • 1
  • 3