Ending tail -f started in a shell script
Posted
by
rangalo
on Stack Overflow
See other posts from Stack Overflow
or by rangalo
Published on 2010-01-11T11:21:04Z
Indexed on
2012/10/10
21:38 UTC
Read the original article
Hit count: 231
I have the following.
- A Java process writing logs to the stdout
- A shell script starting the Java process
- Another shell script which executes the previous one and redirects the log
- I check the log file with the
tail -f
command for the success message.
Even if I have exit 0 in the code I cannot end the tail -f
process.
Which doesn't let my script to finish. Is there any other way of doing this in Bash?
The code looks like the following.
function startServer() {
touch logfile
startJavaprocess > logfile &
tail -f logfile | while read line
do
if echo $line | grep -q 'Started'; then
echo 'Server Started'
exit 0
fi
done
}
© Stack Overflow or respective owner