How to access X display from a cron job when using gdm3?
I would assume to try come up with a script which would execute a shell (in login mode, or set the $HOME variable) and access the Xsession. I would doubt this since executing a cronjob would not provide a valid tty for the process and inturn would be difficult to access the Xsession. However, I am curious to know what purpose are you trying to solve by accessing your Xsession? like launch an xterm or browser? If you are trying to do this purely for automation on a headless terminals, then I would suggest you look for other alternatives like automation tools with selenium.
Related videos on Youtube
derobert
Updated on September 18, 2022Comments
-
derobert almost 2 years
Possible Duplicate:
Open a window on a remote X display (why “Cannot open display”)?I'm trying to run a cron job that needs access to my X session. I know my X session will always be :0, so part of it is easy:
/30 * * * * DISPLAY=:0 command
but the problem is that gdm3 no longer uses
$HOME/.Xauthority
; instead it uses/var/run/gdm3/auth-for-anthony-XXXXXX/database
where the X's change each login.Other than symlinking
$HOME/.Xauthority
to the GDM3 file each login (or editing crontab each login, etc—automatically in.xsession
of course), is there some way to get the cron job working?-
Admin over 12 yearsmaybe we can come up with a bash script, but needs to know, is the XXs are numbers or letters or both ? is the old one deleted each logout ?
-
Admin over 12 years@HananN. They are letters and numbers, e.g.,
JZ7Kpd
. Probably frommkdtemp
. They likely aren't guessable, and/var/run/gdm3
is 0711, so you can't list it (except as root) -
Admin over 12 yearsEr. You edited this to basically say "what ways can this problem be solved other than the ways it was solved in a duplicate question"? Is there something wrong with those solutions?
-
Admin over 12 years@MichaelMrozek: Well, they're sort of kluge-ish, but they have to be because they're not making any assumptions (e.g., gdm3). Turns out gdm3 offers a different way to do this, somehow, through its system dbus API. Maybe. Haven't figured it out yet. (Honestly: I'm one of the two close votes. Maybe this question would better be closed as a duplicate, then I could ask and hopefully answer a new, separate question on the gdm3 dbus interface.)
-
Admin over 12 years@derobert Ok, a new question sounds good. I'll roll this back and close it
-
-
derobert over 12 yearsWell, (a) the only things required to access an X session are the DISPLAY and (if enabled) the xauth cookies. A controlling terminal, much less tty, is not needed. So all you need for cron is to set
DISPLAY
andXAUTHORITY
, the problem isXAUTHORITY
changes; (b) The purpose is to make adcop
call to the Amarok running in my session (yes, I currently plan to run Amarok 1.4 forever.)—in particular, to make it save the current playlist routinely. -
derobert over 12 yearsWell, I could add another key on login, but that'd be about the same as just copying the existing key on login.
-
derobert over 12 yearsWell, yeah, I could turn off authentication on the X server. Or I could run
su -c 'rm -Rf /'
. Both are generally bad ideas. -
Nikhil Mulley over 12 yearsOk, out of my mind. I would still go on to think, why not try with ssh to the same host with -Y with ForwardX11Trusted directive set in ssh_config. Good luck.
-
derobert over 12 years
ssh -Y
forwards the local display over the SSH session, it does this by connecting locally, so it needsDISPLAY
andXAUTHORITY
. Honestly, I like the spirit of coming up with random workarounds; but there are already several fairly good ones in the question—the symlinking of ~/.Xauthority being the best, IMO. Gilles's answer on the other question has several more. I'm hoping there is a non-woraround way to do this... -
Nikhil Mulley over 12 yearsAgreed but was getting myself over puzzled on this and desperate to see something as workaround over this seemingly known one. Still.. if you think the command is to be executed locally on which the X is running then perhaps grabbing the environment of gdm processid for Xauthority file and perhaps extract/merge with xauth could help I suppose.
-
derobert over 12 yearsOooh, I've found a dbus API—will post an answer once I figure out how to use it. org.gnome.DisplayManager /org/gnome/DisplayManager/Display1 org.gnome.DisplayManager.Display.GetX11AuthorityFile if anyone wants to beat me to it.
-
Nikhil Mulley over 12 yearsWonderful! Looking forward to hear more from ya :-)