1

My crontab is like as follows (I am trying to change my GNOME theme)

crontab -l
0 5 * * * /usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Adapta'
30 21 * * *  /usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Adapta-Nokto'

Also, I created this file

echo $USER
nikhil
cat /etc/cron.allow
nikhil

When I run the command as mentioned in crontab, both of those work.

Could you please tell if I missed out some step?


Edit:

I created a script file, which I execute with cron:

export TERM=xterm-256color
TimeHr=$(date +%H)
if ((${TimeHr}>18 || ${TimeHr}<5)); then
#if [${TimeHr} -gt 11 || ${TimeHr} -lt 5]; then
    mkdir ${HOME}/Documents/TestNight
    /usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Adapta'
else
    mkdir ${HOME}/Documents/TestDay
    /usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Adapta-Nokto'
fi

This is crontab

$ crontab -l
36 5,19,23 * * * bash /home/nikhil/GnomeThemeChange
@reboot bash /home/nikhil/GnomeThemeChange

cron does work as it is able to create Test Folders. But, what should I do to run gsettings inside cron?

3

Are you sure cron is not working? If you add a line like

 */1 * * * * touch /tmp/foobar123

to your crontab, then does the file appear in /tmp?

If that file won't appear after a minute or so, then

ps auxw | grep cron

or

sudo service cron status

If cron is not running, then try to start it with

sudo service cron start

But I guess the problem with your command above is, that gsettings needs to have its environment set up correctly in order to run, which it probably does not have, when run from cron.

1

Thanks to Tomáš Pospíšek for the suggestions.

Add the following to the script:

PID=$(pgrep gnome-session | tail -n1)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)

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.