質問

I have a script for following a log file to determine if a server has started, and it goes something like this:

echo "Starting server."
./start_server.sh

sleeptime=0
while [ ${sleeptime} -lt 60 ]
do
    sleep 5

    serverlog=$(tail -n 5 ./server.log)
    echo ${serverlog} | grep -iq "Server startup"

    if [ $? = 0 ]
    then
        echo "Server startup successful"
        exit 0
    fi

    let sleeptime=sleeptime+5
done

echo "Warning: server startup status unknown."
exit 1

When I run the script (./start_server.sh), the script exits fine. However, when I pipeline it to tee (./start_server.sh | tee -a serverstartup.log), the script doesn't end unless I force it (ctrl + C).

Why doesn't the script exit when pipelined to tee?

役に立ちましたか?

解決

The server script spawned a child process that never terminated because it started up a daemon. tee was waiting for the child process to terminate, resulting in this issue.

More details here: Why does tee wait for all subshells to finish?

他のヒント

change :

while [ ${sleeptime} -lt 60 ]

to

while [ ${sleeptime} -le 60 ]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top