User Crontab + Python + Random Wallpaper = Doesn't work?

I have a python script that correctly sets the desktop wallpaper via gconf to a random image in this folder.

Then I have the following entry in my crontab

* * * * * python /home/bolster/bin/change-background.py

And syslog correctly reports

Apr 26 14:11:01 bolster-desktop CRON[9751]: (bolster) CMD (python /home/bolster/bin/change-background.py)
Apr 26 14:12:01 bolster-desktop CRON[9836]: (bolster) CMD (python /home/bolster/bin/change-background.py)
Apr 26 14:13:01 bolster-desktop CRON[9860]: (bolster) CMD (python /home/bolster/bin/change-background.py)
Apr 26 14:14:01 bolster-desktop CRON[9905]: (bolster) CMD (python /home/bolster/bin/change-background.py)
Apr 26 14:15:01 bolster-desktop CRON[9948]: (bolster) CMD (python /home/bolster/bin/change-background.py)
Apr 26 14:16:01 bolster-desktop CRON[9983]: (bolster) CMD (python /home/bolster/bin/change-background.py)

But no desktop, any ideas?

+5
source share
3 answers

Your script depends on the environment variable DISPLAYthat is set when the script is executed from the shell in the X session, but not executed when the script is run from cron.

+6
source

As with Bolo's observation, I forgot about creating in DISPLAY in either a script or crontab.

crontab env DISPLAY=:0.0

:

* * * * * env DISPLAY=:0.0 python /home/bolster/bin/change-background.py
+2

DISPLAY, crontab. , script (#!/usr/bin/env python), . , crontab PWD, HOME.

crontab :

DISPLAY=:0.0
* * * * * bin/change-background.py

PATH ( , DISPLAY), bin/ .


crontab , . , :

PATH=$HOME/bin:$PATH
+2

All Articles