Looks good, except that that doesn't stop after finding the first user so that I get
$ displaynum=0 $ user=`w -hs | awk '{ if ($3 == ":'$displaynum'" || $2 == ":'$displaynum'" ) print $1; }'` $ echo $user kevmitch kevmitch kevmitch kevmitch kevmitch kevmitch kevmitch The following seems to return a unique value however: $ user=`w -hs | awk '{ if ($3 == ":'$displaynum'" || $2 == ":'$displaynum'" ) {print $1;nextfile}; }'` $ echo $user kevmitch Not sure if that's necessarily the "correct" way to do it but it seems to work in my case. Kevin PS: When does displaynum appear in the tty column? On Sun, Sep 7, 2008 at 1:19 AM, Bart Samwel <[EMAIL PROTECTED]> wrote: > Hi Kevin, > > Kevin Mitchell wrote: >> Looking a littler closer, there are more problems than just this typo. >> >> *) This loop is attempting to match "$displaynum" rather than ":$displaynum" >> *) Variables inside the "| while read" construct are only local to within the >> loop (probably because it's executed in some sort of subshell or something), >> so $user never actually gets set. I tried to export it, but that >> didn't work eiither. Instead, the patch attached (again to be >> applied to power-funcs file itself) reverts back to something >> closer to the old method, but using "w" instead of "finger" as >> this was noted to be more reliable. > > Thanks for the scrutiny -- apparently I failed to test this batch of > changes, blindly trusting the fact that I copied most of it from > laptop-mode-tools. Stupid me. Anyway, the reason to go to the "read" > construct was also the fact that filtering for ":0" would also match a > significant percentage of all logged in times (the fourth column in the > output of "w", and also present in the finger output). And it also > matches entries which contain :0.0, which are present for terminal > emulators. We really need to check only the second and third columns for > display numbers, and we need to do exact matches only. So I think I'll > go for this awk-based solution: > > user=`w -hs | awk '{ if ($3 == ":'$displaynum'" || $2 == > ":'$displaynum'" ) print $1; }'` > > Does that work for you? > > Cheers, > Bart > -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]