Results 1 to 6 of 6
Hi,
from a bash script, i invoke a program ./foobar that creates a logfile.txt . Now I want to view the contents of logfile.txt while ./foobar is writing to it, ...
- 10-18-2011 #1Just Joined!
- Join Date
- Oct 2011
- Posts
- 2
tail -f until another program exists?
Hi,
from a bash script, i invoke a program ./foobar that creates a logfile.txt . Now I want to view the contents of logfile.txt while ./foobar is writing to it, but only until ./foobar finished.
So, e.g. I could use:
...but then I get stuck in tail.Code:./foobar & tail -f logfile.txt
Is there an (elegant) way to do this?
Lars
- 10-19-2011 #2
./foobar | less
Surely not exactly what you're looking for, but this is the best thing I come up with.
- 10-19-2011 #3Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
To slightly modify (i.e., complicate) K's suggestion:
Code:#!/bin/sh ./foobar >logfile.txt 2>&1 & while ps -p $! >/dev/null 2>&1; do clear cat logfile.txt sleep 1 done
- 10-22-2011 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Change foobar to write to stdout. Then you can do this:
If you still want the output to go to logfile.txt, then you can insert the tee command, as in:Code:./foobar | tail -f
Code:./foobar | tee logfile.txt | tail -f
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-23-2011 #5Just Joined!
- Join Date
- Oct 2011
- Posts
- 2
solved
thanks everybody.
today, i found another solution: tail has an --pid option!!
Code:./foobar & foobar_pid=$! tail -f logile.txt --pid=$foobar_pid
- 10-24-2011 #6Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
That is completely the best way, thanks for posting solution!


Reply With Quote