You are not logged in.

#1 2011-04-25 19:17:53

XionZui
Member
Registered: 2011-04-25
Posts: 9

Peculiar cron/gsettings issue [SOLVED]

08/2012 Update: For anyone who finds this looking for a solution to this issue, it seems gnome has changed something and cron now needs the DBUS_SESSION_BUS_ADDRESS environment variable set rather than XAUTHORITY. There are a couple methods to get this, but the one I use is a script that runs on login which just runs "echo $DBUS_SESSION_BUS_ADDRESS > ~/.dbus-session". After that, my wallpaper script just needs to read the file and export it before running gsettings set. A more robust way would be to fetch it from gnome-shell's environment like so:

cat /proc/$(pgrep -u `whoami` ^gnome-shell$)/environ | grep -z DBUS_SESSION_BUS_ADDRESS

You can use this in a wallpaper script to output the appropriate value (including DBUS_SESSION_BUS_ADDRESS=) which you can then wrap with $() and export:

export $(cat /proc/$(pgrep -u `whoami` ^gnome-shell$)/environ | grep -z DBUS_SESSION_BUS_ADDRESS)

Original post below:

What I'm trying to do is have cron change my gnome 3 wallpaper every 15 minutes. My crontab looks like this:

00,15,30,45 * * * * gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)"

Now my issue is that when I reboot, this does not function as it should. My wallpaper is not changed, nor is the gsettings key value. However, if I manually restart the cron daemon after I've logged in, it begins to function again. This issue is present with both fcron and dcron. The issue doesn't seem to be that cron is not running the jobs; here's my crond.log including 2 instances of the jobs that did not work as expected:

Apr 25 13:45:00 localhost fcron[3116]: Job gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)" started for user xion (pid 3117)
Apr 25 13:45:03 localhost fcron[3116]: Job gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)" completed
Apr 25 13:47:51 localhost fcron[2874]: Job /usr/sbin/run-cron /etc/cron.daily completed (mailing output)
Apr 25 13:47:51 localhost fcron[2874]: Can't find "/usr/sbin/sendmail". Trying a execlp("sendmail"): No such file or directory
Apr 25 13:47:51 localhost fcron[2874]: Can't exec /usr/sbin/sendmail: No such file or directory
Apr 25 13:47:51 localhost fcron[4234]: Job /usr/sbin/run-cron /etc/cron.hourly started for user systab (pid 4235)
Apr 25 13:47:53 localhost fcron[4234]: Job /usr/sbin/run-cron /etc/cron.hourly completed
Apr 25 14:00:00 localhost fcron[5157]: Job gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)" started for user xion (pid 5158)
Apr 25 14:00:02 localhost fcron[5157]: Job gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)" completed

So the job is being run, but it refuses to actually apply the change until I restart the daemon. What could be the cause of this issue?

Update: Turns out I needed to set DISPLAY and XAUTHORITY for gsettings to be able to set anything. Is there a better way to set these or fetch them from the desktop shell than simply using export in the cron job script?

Last edited by XionZui (2012-11-01 03:27:00)

Offline

#2 2011-04-25 20:20:20

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,531
Website

Re: Peculiar cron/gsettings issue [SOLVED]

Three suggestions:
1. You need absolute paths in cronjobs. You can't use '~' for your home directory
2. That's a pretty long set of commands...perhaps they're better suited to be in a script called by cron. (Again, don't forget you will need to use absolute paths in the script, too)
3. I think that */15 * * * * will run every 15 min as well.

Scott

Offline

#3 2011-04-25 21:18:23

XionZui
Member
Registered: 2011-04-25
Posts: 9

Re: Peculiar cron/gsettings issue [SOLVED]

No luck on any front

Apr 25 15:45:50 localhost fcron[2405]: adding new file xion
Apr 25 15:46:50 localhost fcron[2405]: updating configuration from /var/spool/fcron
Apr 25 15:46:50 localhost fcron[2405]: adding new file xion
Apr 25 16:00:00 localhost fcron[6003]: Job gsettings set org.gnome.desktop.background picture-uri "file://$(find /home/xion/Pictures/Wallpapers -type f | shuf -n1)" started for user xion (pid 6004)
Apr 25 16:00:02 localhost fcron[6003]: Job gsettings set org.gnome.desktop.background picture-uri "file://$(find /home/xion/Pictures/Wallpapers -type f | shuf -n1)" completed
Apr 25 16:01:00 localhost fcron[6018]: Job /usr/sbin/run-cron /etc/cron.hourly started for user systab (pid 6019)
Apr 25 16:01:02 localhost fcron[6018]: Job /usr/sbin/run-cron /etc/cron.hourly completed
Apr 25 16:03:41 localhost fcrontab[6032]: fcrontab : editing xion's fcrontab
Apr 25 16:04:50 localhost fcron[2405]: updating configuration from /var/spool/fcron
Apr 25 16:04:50 localhost fcron[2405]: adding new file xion
Apr 25 16:15:00 localhost fcron[6072]: Job /home/xion/Scripting/gnome-desktop.sh started for user xion (pid 6073)
Apr 25 16:15:02 localhost fcron[6072]: Job /home/xion/Scripting/gnome-desktop.sh completed

Could it be related to read permissions on my home folder or gsettings not modifying the correct user settings? Is there any way to see the output of the commands when they're run? What could possibly be changed by restarting the cron daemon with sudo?

Edit: Alright, I've narrowed it down a little bit. It's successfully running the script. gsettings get works fine, the find and shuf commands work fine and output a string in the appropriate format, and I can have it write to a text file. The only thing that won't work for whatever reason is gsettings set, and it doesn't give any errors (or any output at all) when it runs. I've tried it with multiple keys and simple integer values, and it simply won't change anything. Is there possibly an environment variable that needs to be set for it to work properly which isn't set when cron is started at boot?

Last edited by XionZui (2011-04-26 00:50:36)

Offline

#4 2011-05-27 17:58:27

giacomo
Member
Registered: 2011-05-27
Posts: 1

Re: Peculiar cron/gsettings issue [SOLVED]

Hi XionZui,
I may be a bit late... I see this thread has been marked as [SOLVED] but it seems not to be so (at least I can't see the solution posted here).

I had the same issue as you, it turns out that the solution is quite simple, try with this:

*/15 * * * * DISPLAY=:0 GSETTINGS_BACKEND=dconf  gsettings set org.gnome.desktop.background picture-uri "file://$(find ~/Pictures/Wallpapers -type f | shuf -n1)"

That should do the trick - actually, I made a script and have this line into it:

DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri "file://${picture}"

Where I pre-set the $picture variable, taking it from a list.
Did you figure it out already?

Cheers,
Giacomo.

Offline

Board footer

Powered by FluxBB