Hi Phil,

Phil Endecott wrote:
> I've just spotted detect_x_display() in
> /usr/share/eeepc-acpi-scripts/functions.sh from package
> eeepc-acpi-scripts which does a similar thing by parsing the output of
> "who", rather than "finger".  "who" has the advantage of being provided
> by coreutils, which is a "Priority: required" package, while finger is
> "Priority: standard".  There is also "w" from procps.
> 
>> the format provided by finger is (:$displaynum) or
>> (:$displaynum.screennum).
> 
> Err, no; mine doesn't have the ():
> 
> $ finger
> Login     Name            Tty      Idle  Login Time   Office     Office
> Phone
> phil      Phil Endecott  *tty1    14:51  Sep  2 16:40
> phil      Phil Endecott   pts/0          Sep  4 12:09 (egypt.chezphil.org)
> phil      Phil Endecott  *:0             Sep  4 12:29
> root      root           *tty2    13:02  Sep  3 21:40
> 
> Obviously yours does and I'm sure I've seem that notation somewhere or
> other; I don't know if the () mean something or whether it's a finger
> version thing, or what.

Mine actually only lists the display in the Office column:

$ finger
Login     Name       Tty      Idle  Login Time   Office     Office Phone
bsamwel   bsamwel    tty7           Sep  4 11:36 (:0)
bsamwel   bsamwel    pts/2          Sep  4 11:37 (:0.0)
root      root      *tty1        1  Sep  4 14:17
root      root      *tty2        1  Sep  4 14:18
root      root       pts/1      25  Sep  4 11:37 (:0.0)

So that's a bit strange. I like the "w" approach, I've already got a bit
of code in laptop-mode-tools that uses "w -hs". I've now got:


getXuser() {
        w -hs | while read -r THIS_USER THIS_TTY THIS_DISPLAY DUMMY_REMAINDER; 
do
                if [ "$THIS_DISPLAY" = "$displaynum" ] ; then
                        user=$THIS_USER
                        break
                fi
        done
        if [ x"$user" = x"" ]; then
                startx=`pgrep -n startx`
                if [ x"$startx" != x"" ]; then
                        user=`ps -o user --no-headers $startx`
                fi
        fi
        if [ x"$user" != x"" ]; then
                userhome=`getent passwd $user | cut -d: -f6`
                export XAUTHORITY=$userhome/.Xauthority
        else
                export XAUTHORITY=""
        fi
        export XUSER=$user
}


This does the trick for me. Does it work for you? If so, I'll use that.

Cheers,
Bart



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to