I have a simple script file startsql.sh
to start mysql:
#!/bin/bash
#Script to Start MySQL
echo "Starting MySQL"
if sudo service mysqld start; then
echo "MySQL started successfully!"
else
echo "Error: Failure to start MySQL" 1>&2
exit 1
fi
I run it using:
bash startsql.sh |& tee -a scriptlogs.log
Though the service seems to start successfully, the command hangs after showing the messages on the command window. It works fine without hanging if I remove the tee. Interestingly I have a similar script to stop mysql and it works fine without issues. I checked and find no difference between the two scripts.
After searching a lot, I found that using the below works, but the side effect of this is that the tee process is still running in the background
bash startsql.sh > >( tee -a scriptlogs.log) 2>&1
Can someone please help me understand why does using tee hang on some occasions.