Skip to main content
Topic: [SOLVED] Problem with $DISPLAY env variable (Read 1191 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[SOLVED] Problem with $DISPLAY env variable

Hello. I installed artix this week and everything is going perfectly. But i have this issue with the $DISPLAY variable.

I'm using crontab and to be able to use notify-send i have to set the display variable. But for some reason echo $DISPLAY outputs a different number everytime. This morning it was :6 and after a reboot now its :7, in arch it was always :0. Anybody knows how to fix this? I couldn't find any information online.

Re: Problem with $DISPLAY env variable

Reply #1
I don't think you should ever be setting $DISPLAY manually. That should be done automatically whenever you start up a graphical session.

 

Re: Problem with $DISPLAY env variable

Reply #2
Move the whole session to another VT
If tty terminals 3-6 are not used and commented out (You may use screen and therefore only need one terminal), change /etc/X11/xinit/xserverrc:
Code: [Select]
exec /usr/bin/X -nolisten tcp vt07

Re: Problem with $DISPLAY env variable

Reply #3
I don't think you should ever be setting $DISPLAY manually. That should be done automatically whenever you start up a graphical session.

For notify-send to work on crontabs it have to be set for cronie.

Move the whole session to another VT
If tty terminals 3-6 are not used and commented out (You may use screen and therefore only need one terminal), change /etc/X11/xinit/xserverrc:
Code: [Select]
exec /usr/bin/X -nolisten tcp vt07

How can i comment out the tty 3-6? I tried to change
Code: [Select]
exec /usr/bin/X -nolisten tcp vt07
but at boot xorg outputs that it has no permission for it. So i changed it back to
Code: [Select]
exec /usr/bin/X -nolisten tcp "$@"
and now $DISPLAY is :0 again so for some reason it keeps changing.

Re: Problem with $DISPLAY env variable

Reply #4
Could you get the DISPLAY dynamically at runtime in the command?
Something like this might work although on a server with multiple displays you would need to find the correct one, but I only tried it in the terminal, not with cron:
Code: [Select]
$ DISPLAY=$(ls /tmp/.X11-unix | head -n1 | tr 'X' ':')".0" notify-send Hey "How are you?"
This link suggests this as a current working solution for someone too, and it also works in my terminal, but so does plain notify-send.
 
Code: [Select]
XDG_RUNTIME_DIR=/run/user/$(id -u) notify-send Hey "this is dog!"
https://stackoverflow.com/questions/16519673/cron-with-notify-send
https://unix.stackexchange.com/questions/17255/is-there-a-command-to-list-all-open-displays-on-a-machine
I wonder why the number keeps changing though, because that seems unusual. Is X crashing and being restarted at boot or something? Perhaps check syslog and .local/share/xorg/Xorg.0.log (& .old) for clues? Or is there some config resetting it?

Re: Problem with $DISPLAY env variable

Reply #5
Could you get the DISPLAY dynamically at runtime in the command?
Something like this might work although on a server with multiple displays you would need to find the correct one, but I only tried it in the terminal, not with cron:
Code: [Select]
$ DISPLAY=$(ls /tmp/.X11-unix | head -n1 | tr 'X' ':')".0" notify-send Hey "How are you?"
This link suggests this as a current working solution for someone too, and it also works in my terminal, but so does plain notify-send.
 
Code: [Select]
XDG_RUNTIME_DIR=/run/user/$(id -u) notify-send Hey "this is dog!"
https://stackoverflow.com/questions/16519673/cron-with-notify-send
https://unix.stackexchange.com/questions/17255/is-there-a-command-to-list-all-open-displays-on-a-machine
I wonder why the number keeps changing though, because that seems unusual. Is X crashing and being restarted at boot or something? Perhaps check syslog and .local/share/xorg/Xorg.0.log (& .old) for clues? Or is there some config resetting it?

It looks today that it keeps it at :0 i don't know why. I implemented your solution to crontab it works great!

I checked the syslog and xorg log and i have the same errors i had ever: some acpi bios bugs and this:
Code: [Select]
[   13.475810] elogind[1145]: Failed to connect to system bus: No such file or directory
[   13.475815] elogind[1145]: Failed to fully start up daemon: No such file or directory
Which i took a look internet and looks like it's harmless.
So i don't know why that happens.

Alright i decided to settle up with the dynamic fix to detect the display. Thanks!