1

On my Ubuntu 20 desktop, I've scheduled gedit to run a minute from now, but nothing happens. Why is that?

$ echo "echo foo > at.sux" | at now + 1
warning: commands will be executed using /bin/sh
job 8 at Tue Jun  2 21:47:00 2020

$ echo `which gedit` | at now + 1
warning: commands will be executed using /bin/sh
job 9 at Tue Jun  2 21:47:00 2020

$ atq
9   Tue Jun  2 21:47:00 2020 a dandv
8   Tue Jun  2 21:47:00 2020 a dandv

# A minute later

$ cat at.sux
foo

$ ps auxf | grep gedit  # nothing but grep

$ `which gedit`  # launches gedit

I tried echo "gedit &" | at now + 1 as suggested in the comment, but gedit is still not running a minute later.

2 Answers2

5

GUI applications access the screen through a server. When you run them from the command line or the menu, the environment tells the application how to connect to the server.

When you run an at command though, the environment does not include that information (you can do at -c JOBNUMBER to see the environment the application inherits) and that's why the application will start, but not be able to run.

To run a GUI application you could specify the server, either calling the application with something this (your display might be different):

DISPLAY=:0 application

or, depending on the application:

application --display :0

You might need to change the server permissions and other services might be needed and not accessible from outside the session though (things like dbus).

0

GUI applications such as gedit may or may not work with the at command. It depends on whether you are using an X11-based display server such as Xorg or a server based on the Wayland protocol such as Weston.

Which display server is used depends on your distribution, the version of the distribution, and user configuration. For example, by default, Ubuntu 20 uses an X11-based display server whereas Fedora 32 uses Wayland.

The at command stores most of your current environment in a at job file under /var/spool/at. There are a few exceptions including DISPLAY, TERM, SHELLOPTS, EUID, GROUPS, PPID, UID, and a couple more. These are specifically not stored in the at job file.

Thus, if you create an at job to launch a GUI application in an X11-based server environment, it will fail because no DISPLAY variable is available.

The workaround is simple (assuming your screen is :0):

$ echo 'DISPLAY=:0 gedit' | at now + 1 min

or more generally:

$ echo 'DISPLAY="$DISPLAY" gedit' | at now + 1 min

Wayland uses a different environmental variable, i.e. WAYLAND_DISPLAY, which is typically set to wayland-0. The at command preserves this variable and, thus, the GUI application is launched when the at job runs.

fpmurphy
  • 4,636