3

I am running a nearly fresh image of Raspbian Stretch 4.9 with a desktop and have a program which creates a new image for the computer background every few minutes.

I am trying to create a cron job to properly update the background using pcmanfm and, having followed the suggestions here, have created the following script called update.sh to set the background:

!#/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/pi/.Xauthority
pcmanfm -w '/home/pi/folder/image.png'

The script is executable and when it is run from the terminal it functions as intended. I have created a crontab to have this run automatically as such:

* * * * * /home/pi/folder/update.sh > /home/pi/folder/log.txt 2>&1

When the cron job triggers every minute, a pop-up window appears with an error saying "Desktop manager is not active." with a button "OK" to dismiss it, and the log file reads:

** Message: x-terminal-emulator has very limited support, consider choose another terminal

I have tried the command directly in the crontab

* * * * * DISPLAY=:0 && pcmanfm -w '/home/pi/folder/image.png' > /home/pi/folder/log.txt 2>&1

And the error is different this time

Cannot open display:

I am not entirely sure what sense to make of this, though from looking around it seems cron jobs can be finnicky. I am not sure if it is a Path or environment problem because I do not know many details about these things, but I don't think it should be a problem as I am using the full path to the image and the scripts. It shouldn't be a permissions error, because I have tried this on both a user crontab and a system crontab, and both fail. (Besides, the default pi user has root permissions by default anyways.) I am not sure what else to search for or try so I am asking for help if someone could point me in the right direction or has encountered this problem before.

  • after running an update on my laptop last night (which included updating pcmanfm) my script that did the same thing stopped working. I'm guessing the cron-launched script is not running in the same "user space" as the graphically-logged-in user, and so there's some environment variable not being set correctly. Unfortunately, I am not an expert linux user, but I will continue to dig around and post back if I find a solution. TLDR: I think a recent update broke it. – Russell Uhl Sep 05 '17 at 12:34
  • if i remember correctly you don't want the `&&` in the all-in-a-crontab™️ version. i.e. `* * * * * DISPLAY=:0 pcmanfm -w '/home/pi/folder/image.png' > /home/pi/folder/log.txt 2>&1`. dunno if that'll work tho as nothing to test on – northern-bradley Apr 14 '23 at 12:15

1 Answers1

6

I had exactly the same issue, except I am running Lubuntu 17.04. It appeared lately after a recent update, though cannot pinpoint when. After lot's of research I became suspicious that one of the XDG enviromental variables must be exported too. Following some trial and error, I found that exporting XDG_RUNTIME_DIR solved the problem for me. You may want to give it a try.

To figure out the value run: echo $XDG_RUNTIME_DIR

The working wallpaper changer running from cron for me now looks like:

#!/bin/bash
...
export DISPLAY=:0
export XAUTHORITY=/home/krisz/.Xauthority
export XDG_RUNTIME_DIR=/run/user/1000
pcmanfm --set-wallpaper=${dir}/${file} --wallpaper-mode=crop
...