[comp.unix.questions] awk gacks with grep

harkcom@potato.pa.Yokogawa.CO.JP (Alton Harkcom) (07/07/90)

   I don't understand...

   I used a textbook example from Kernighan and Pike "The UNIX Programming
Environment" and then hit it with grep and it bellied up...

#sentry program to let me know when somebody logs on or off
#from page 147 "The UNIX Programming Environment" by Kernighan and Pike

# watchwho: watch who logs in and out

#PATH=/bin:/usr/bin    # I don't need it
new=/tmp/wwho1.$$
old=/tmp/wwho2.$$
>$old                  # create empty file

while :                # loop forever
do
	who >$new
	diff $old $new
	mv $new $old
	sleep 60
done | awk '/>/ && !/harkcom/ { $1 = "in:  "; print }
            /</ && !/harkcom/ { $1 = "out: "; print }' 
#end


   I typed "sentry &" (after setting it up) and it worked fine...

   Today I decided I was tired of seeing my own name appear every time I opened
a new window in X. I typed "sentry | grep -v harkcom &" and I got nothing. I 
logged in and out as other users many times (staying on for 2-3 minutes each
time) yet nothing came out.

   I put grep directly after awk:

done | awk '/>/ && !/harkcom/ { $1 = "in:  "; print }
            /</ && !/harkcom/ { $1 = "out: "; print }' | grep -v harkcom

   but no output. Then I took out awk and left grep. I got the diff lines for
the other users as expected. I then returned it to its original form and tried
it as usual. Again no problems. Then I tried "sentry > /tmp/sentry.tmp" and let
it run while I rlogged in and out on another terminal for a while. Then I
interrupted sentry and looked at /tmp/sentry.tmp. It was empty...

   Is there something about the way that awk buffers that I need to know?

   I fixed the problem by adding the awk script to skip my name but I still
want to know ?why?

   Help...




--
--harkcom@potato.pa.yokogawa.co.jp