Cron job doesn't work after update to 24.04

Ubuntu Version: 24.04.2 LTS

Desktop Environment (if applicable): GNOME

Problem Description:
This cron job
‘’’
0 18 * * 5 export DISPLAY=:0.0; gedit System/Msgs/RNS
‘’’
does not work since I upgraded from 18.04 LTS. Before that it opened the RNS file in a gedit window at 6pm every Friday

Screenshots or Error Messages:
The error messsage I have managed to capture is
‘’’
(gedit:19290): Gtk-WARNING **: 20:22:01.861: cannot open display: :0.0
Authorization required, but no authorization protocol specified
‘’’
The second line, about authorisation, does not always appear.

What I’ve Tried: I have run the following variant to capture the error messages
‘’’

          • export DISPLAY=:0.0; gedit System/Msgs/Backup 2>>/home/george/System/cron.log
            ‘’’

Maybe a silly response but the logged in user is on an X11 session correct?

To see if you are using the correct dispaly, open terminal and run: echo $DISPLAY and if it shows :0 that’s not the problem.

If you want to open a file in gedit or another text editor, you need to indicate the path so it can be found. You are showing gedit looking for a file at System/Msgs/RNS so where exactly is that file? Do you have an actual System directory and if so where is it? If it is in the / (root of the filesystem) you would need to prefix the path with /.

I don’t understand the question; What other kind of session might it be, and how do I know?

echo $DISPLAY shows:0
The files is at /home/george/System/Msgs/RNS. I have modified the job accordingly, and it makes no difference

I have also adjusted the file permissions for the text files to have system wide read access. That made no difference either.

You can see if you are in a X11 or Wayland session through the terminal:

echo "$XDG_SESSION_TYPE"

In my wayland session it responds with:

wayland

I tested this by creating a System directory in my /home/user directory, then a Msgs directory in System and a file named RNS in the Msgs directory and the entry below opened the file with gedit:

00 17 * * * export DISPLAY=:0 && gedit /home/user/System/Msgs/RNS

My system behaves the same way

That does not immediately work for me.
However, I realise that, since the update, read access to all my files (ie everything in Home) is restricted to me. I need to properly explore/fix this, alas when real life permits.

I have now tried this after ensuring that the RNS text file is readable by everybody. It does not work for me. The logfile (/var/log/syslog ) gives the error message “(No MTA installed, discarding output)”

Do an online search for that error and you will find a number of sites discussing it such as the one at the ink below. It should not effect the cron job output. MTA is mail transfer agent.

https://cronitor.io/guides/no-mta-installed-discarding-output

I don’t know why the cron entry doesn’t work for you as it works fine for me.

Are you really wanting to open the file in gedit or are you just testing opening a GUI app using cron?

If you installed 24.04 from scratch, gedit is not included in the default packages.

Open a terminal
apt policy gedit

What I really want this cron job to do is to display a text message on the screen. (eg “backup will run automatically in 30 minutes, Please ensure that the removable back up device is connected”). I could use notify (but that is too transient) or email (but that would not usually get my attention) so I opted for opening a text file with gedit (my default, but apparently obsolescent, text editor).

gedit is certainly installed on my system - I use it as my default text editor

Thank you for your help. I agree that the MTA message is a red herring - I don’t see why the presence or otherwise of an MTA stops a cron job from working.
I’m afraid we both remain puzzled

Try this instead of having it pop-up a text editor:

zenity --title "Backup Notification" \
       --info \
       --text="Backup will run automatically in 30 minutes. \
Please ensure that the removable backup device is connected."

That will display this:

image

2 Likes

That is exactly what I want to do, and it works from the command line. But when I put it in a cron job I get an error
“(zenity:17030): Gtk-WARNING **: 22:15:01.903: Failed to open display”

Are you using the root cron or the user cron?

I am using the user cron