0

I am trying to set up crontab to run a script that will pick a random image from a folder and set it as my wallpaper in the morning, and another script that will do the same thing at night.

Goal is to have a random day and night wallpaper.

Got everything to work for a while by following the instructions from this post.

With this code:

#!/bin/bash

DIR="/path/to/wallpapers/" PIC=$(ls $DIR/* | shuf -n1) PID=$(pgrep gnome-session); export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-); gsettings set org.gnome.desktop.background picture-uri "file://$PIC"

But my wallpaper just stopped updating after a day or so. I just tried setting cron to run this script every minute in an attempt to troubleshoot it (since that had worked in my tests before), but it just won't update my wallpaper anymore...

Does anyone know what could be the issue? Or know a better way/script to do it?

This is the full error message:

grep: /proc/1069: Is a directory
grep: 1501/environ: No such file or directory

(process:11303): dconf-CRITICAL **: 23:22:01.548: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

(process:11303): dconf-CRITICAL **: 23:22:01.548: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

(process:11303): dconf-CRITICAL **: 23:22:01.549: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

(process:11303): dconf-WARNING **: 23:22:01.549: failed to commit changes to dconf: The given address is empty

Thanks in advance

-- Running Ubuntu 18.04

dazzmos
  • 21
  • Have you tried redirecting the standard error stream to a log file, and examining its contents for clues as to why the script is failing? – steeldriver Aug 01 '20 at 01:23
  • no, I am not sure how I would do that... Would you mind letting me know I would be able to redirect the error stream? – dazzmos Aug 01 '20 at 01:59
  • ... add 2>/tmp/cron.log to your cronjob (or >/tmp/cron.log 2>&1 if you want to log both stderr and stdout) – steeldriver Aug 01 '20 at 02:09
  • Thanks, I updated the post with the error. – dazzmos Aug 01 '20 at 02:32
  • I suspect the issue is that pgrep gnome-session is returning more than a single PID – steeldriver Aug 01 '20 at 02:35
  • Yes it is. It outputs: 1069 and 1501. I am confused as to why – dazzmos Aug 01 '20 at 02:41
  • maybe its enough to add -n to pgrep –  Aug 01 '20 at 06:44
  • 1
    I've posted number of answers about the same task. Pleas see also: Cannot change desktop background with crontab and Why does this cronjob not work?. Here is a complete manual: https://github.com/pa4080/cron-gui-launcher – pa4080 Aug 01 '20 at 07:35
  • @bac0n adding the -n to pgrep has made it work again. Unsure if it will suddenly stop like before though, will give it a try Thanks for your help. @pa4080 I appreciate the posts, I did read them, and don't doubt the answer to my problem is there. But I lack knowledge on the topic (still fairly new to Linux), so a lot of the words just didn't mean much to me yet :/ Gonna see if the -n, has done it, otherwise I will look further into them, thanks. – dazzmos Aug 01 '20 at 16:45
  • So far it has been working, however it still outputs errors::

    /path/to/script.sh: line 6: warning: command substitution: ignored null byte in input

    (process:5866): dconf-CRITICAL **: 14:00:01.807: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

    – dazzmos Aug 01 '20 at 17:11
  • try to move/delete it, just a cache folder –  Aug 01 '20 at 20:10
  • Another option that you can use that has similar functionality is Variety: https://github.com/varietywalls/variety – guttermonk Aug 02 '20 at 02:11
  • @bac0n the folder is owned by root, which is why I get the error in the first place. It works right now, and all I get is a log file, I am fine with that... guttermonk, I will look into it if this ever breaks, thanks! – dazzmos Aug 05 '20 at 14:43
  • Everything is still working, so I guess the problem was solved. I am unsure what to do with the similar questions that were suggested as answers to this one. Given that the fix came from one of the comments here... – dazzmos Aug 05 '20 at 14:44

1 Answers1

0

An easy workaround : run from user cron

If you script is run by your user (from the user crontab), then you do not need to address the dbus system.

#!/bin/bash
DIR="/path/to/wallpapers/"
PIC=$(ls $DIR/* | shuf -n1)
/usr/bin/gsettings set org.gnome.desktop.background picture-uri "file://$PIC"
cmak.fr
  • 8,696
  • I am running crontab -e to create the cron file. I believe this creates a user crontab, which is run by the user, correct? I am unsure if I am missing something, but I have tested it with your code and still get the errors in the comment below: – dazzmos Aug 01 '20 at 15:33
  • (process:4548): dconf-CRITICAL **: 12:26:01.612: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

    (process:4548): dconf-CRITICAL **: 12:26:01.612: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

    (process:4548): dconf-CRITICAL **: 12:26:01.613: unable to create file '/home/user/.cache/dconf/user': Permission denied. dconf will not work properly.

    (process:4548): dconf-WARNING **: 12:26:01.613: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY

    – dazzmos Aug 01 '20 at 15:35