LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   How do I get another users $DISPLAY (https://www.linuxquestions.org/questions/linux-desktop-74/how-do-i-get-another-users-%24display-743582/)

micxz 07-29-2009 12:45 AM

How do I get another users $DISPLAY
 
I'm trying to get my girlfriends DISPLAY via script but when I try in the terminal first:

Code:

home:~ # su - -c 'echo $DISPLAY' amber

home:~ # su - -c 'echo $USER' amber
amber

I know her DISPLAY is ":1.0" but why would I be able to get some env vars and not others?

mackdav 07-29-2009 01:15 PM

Environment variables are set by the login context or the program being run (in this case, X). So just by su - ing to her you won't see what her session environment variables are, because when you su - to her, you are creating a new session, not duplicating an existing one.

What are you trying to accomplish?

micxz 07-29-2009 07:07 PM

I'm trying to get her display so I can send graphical notifications to her screen via "notify-send". It's really not that important I'm just playing around. I think I found a way around it by using su and then getting the xauth cookie list import the cookie and then set display to hers and send the popup or other to her screen. When you list xauth cookies they are in the format host:1 for user on host display :1.0 and so on. So I guess this works but it's a funky script I would like to be able to get display var alone but maybe it's not possible. I can see it in /proc/"kdeinit_procnumber"/environ but when I try to grep but it says "binary file matches".

jschiwal 07-29-2009 07:30 PM

The "USER" and "DISPLAY" variables will be part of her environment.

You can grep out the PID of a process she will be using, and then
tr '\0' '\n' /proc/$pid/environ | grep DISPLAY=

I had just posted this, and other things, in your other semi-related post on cron, before reading this thread.

Look at the Xstartup script, if you have it. It does things like parse the DISPLAY variable to tell if it is a local or remote connection.
Code:

# Find out if this is a local or remote connection
#
LOCATION=${DISPLAY%:*}
LINE=:${DISPLAY#*:}
if test -z "$LOCATION" ; then
    # local connection
    case "$LINE" in
        :0|:0.0) LOCATION=console  ;;
        *)      LOCATION=localhost ;;
    esac
else
    # TCP/IP connection (remote or local)
    NAME=${LOCATION%%.*}
    if test -z "${NAME%%*[0-9]}" ; then
        LINE=${LINE}/${LOCATION}
    else
        LINE=${LINE}/${NAME}
    fi
fi


micxz 07-29-2009 08:10 PM

Thank You I'm going to look at this a bit closer.


All times are GMT -5. The time now is 02:47 AM.