1

I wrote the following crontab task which should switch my backgound image every 10 minutes on linux mint:

*/10 * * * * /home/me/Pictures/wallpapers/switcher.sh >> /home/me/Logs/wallpaper.log 2>&1

Which calls this shell script:

#!/bin/bash
gsettings set org.cinnamon.desktop.background picture-uri $(/usr/bin/python3 /home/me/Pictures/wallpapers/spaceBack.py)

In the log file I get this error message:

(process:18951): dconf-CRITICAL **: 14:00:02.264: unable to create file '/home/me/.cache/dconf/user': Permission denied.  dconf will not work properly.
(process:18951): dconf-CRITICAL **: 14:00:02.265: unable to create file '/home/me/.cache/dconf/user': Permission denied.  dconf will not work properly.
(process:18951): dconf-CRITICAL **: 14:00:02.265: unable to create file '/home/me/.cache/dconf/user': Permission denied.  dconf will not work properly.
(process:18951): dconf-WARNING **: 14:00:02.265: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY

I only get this error when running the shell script via cron (it works fine via terminal).

calling ls -la /home/me/.cache/dconf/ Returns

drwx------  2 root  root  4096 Jul  6 16:13 .
drwx------ 48 me me 4096 Jun 29 15:33 ..
-rw-------  1 root  root     2 Jul  6 16:13 user
  • Try echo $DISPLAY and place the resulting value in your cron command like so: DISPLAY=<value returned from echo> /home/me/Pictures/wallpapers/switcher.sh [...] – Panki Jul 6 '20 at 13:53
  • it slightly changed the error message to ... (process:21877): dconf-WARNING **: 16:04:05.657: failed to commit changes to dconf: Could not connect: Connection refused the DISPLAY value is :0 – Chris Jul 6 '20 at 14:04
  • What user is this crontab running as? – Panki Jul 6 '20 at 15:06
  • Seems to be running as me – Chris Jul 6 '20 at 15:12
  • That's most likely the issue - you should use your regular user. – Panki Jul 6 '20 at 15:13
0

DBUS_SESSION_BUS_ADDRESS has to be set as an environment variable. Its proper value can be set via the following script, taken from this question asking How to change Gsettings via remote shell?

#!/bin/bash

# Remember to run this script using the command "source ./filename.sh"

# Search these processes for the session variable 
# (they are run as the current user and have the DBUS session variable set)
compatiblePrograms=( nautilus kdeinit kded4 pulseaudio trackerd )

# Attempt to get a program pid
for index in ${compatiblePrograms[@]}; do
    PID=$(pidof -s ${index})
    if [[ "${PID}" != "" ]]; then
        break
    fi
done
if [[ "${PID}" == "" ]]; then
    echo "Could not detect active login session"
    return 1
fi

QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "${QUERY_ENVIRON}" != "" ]]; then
    export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
    echo "Connected to session:"
    echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
else
    echo "Could not find dbus session ID in user environment."
    return 1
fi

return 0

The cron job can then be modified to this: */10 * * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /home/me/Pictures/wallpapers/switcher.sh >> /home/me/Logs/wallpaper.log 2>&1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.