Frage Script-Setting funktioniert nicht in Cron-Job


Ich habe ein Skript geschrieben, um das Thema meines PCs automatisch zu ändern. Das Skript funktioniert ohne Probleme im Terminal, aber wenn ich es in Cron setze, erhalte ich diesen Fehler

dconf-WARNING **: 02:52:01.932: failed to commit changes to dconf: Conncetion closed

Wie kann ich das beheben? Ich habe stundenlang gegoogelt, aber nichts.

Das ist mein Skript:

AutoThemeSwitzer.sh  
#!/bin/bash 

CurrenTime="$(date +%H)"
NIGHT_TIME=7
DAY_TIME=8
DAY_THEME="Sierra-light"
NIGHT_THEME="Sierra-dark"
USER=robin994

NIGHT_IMAGE_PATH="/home/$USER/Immagini/mojave-night.jpg"
DAY_IMAGE_PATH="/home/$USER/Immagini/mojave-day.jpg"

CT=$(( 10#$CurrenTime-12 ))

if [ $CT -ge 0 ] 
    then
    if [ $CT -ge $NIGHT_TIME ] 
        then 
             gsettings set org.gnome.desktop.interface gtk-theme "$NIGHT_THEME"
             gsettings set org.gnome.desktop.interface gtk-theme "$NIGHT_THEME"
             gsettings set org.gnome.shell.extensions.user-theme name "$NIGHT_THEME"
             gsettings set org.gnome.desktop.background picture-uri "file://$NIGHT_IMAGE_PATH"

        else
             gsettings set org.gnome.desktop.interface gtk-theme "$DAY_THEME"
             gsettings set org.gnome.desktop.interface gtk-theme "$DAY_THEME"
             gsettings set org.gnome.shell.extensions.user-theme name "$DAY_THEME"
             gsettings set org.gnome.desktop.background picture-uri "file://$DAY_IMAGE_PATH"

    fi

elif [ $(( $CT + 12 )) -ge $DAY_TIME ] 
    then 
         gsettings set org.gnome.desktop.interface gtk-theme "$DAY_THEME"
         gsettings set org.gnome.desktop.interface gtk-theme "$DAY_THEME"
         gsettings set org.gnome.shell.extensions.user-theme name "$DAY_THEME"
         gsettings set org.gnome.desktop.background picture-uri "file://$DAY_IMAGE_PATH"
    else
         gsettings set org.gnome.desktop.interface gtk-theme "$NIGHT_THEME"
         gsettings set org.gnome.desktop.interface gtk-theme "$NIGHT_THEME"
         gsettings set org.gnome.shell.extensions.user-theme name "$NIGHT_THEME"
         gsettings set org.gnome.desktop.background picture-uri "file://$NIGHT_IMAGE_PATH"
fi
  

Das ist meine Cron-Datei:

Cron
#Borrowed from anacron
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/robin99$
#End borrowed from anacron


DISPLAY=:0
XAUTHORITY=/home/robin994/.Xauthority
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qQv0mtFe42,guid=f0a53dfd4343da$
DBUS_SESSION_BUS_PID=14893

* * * * * bash -x AutoThemeSwitcher.sh > /home/robin994/bin/auto3.log 2$

Logdatei

++ date +%H
+ CurrenTime=02
+ NIGHT_TIME=7
+ DAY_TIME=8
+ DAY_THEME=Sierra-light
+ NIGHT_THEME=Sierra-dark
+ NIGHT_IMAGE_PATH=/home//Immagini/mojave-night.jpg
+ DAY_IMAGE_PATH=/home//Immagini/mojave-day.jpg
+ CT=-10
+ '[' -10 -ge 0 ']'
+ '[' 2 -ge 8 ']'
+ gsettings set org.gnome.desktop.interface gtk-theme Sierra-dark

(process:19539): dconf-WARNING **: 02:52:01.918: failed to commit changes to dconf: La connessione è chiusa
+ gsettings set org.gnome.desktop.interface gtk-theme Sierra-dark

(process:19543): dconf-WARNING **: 02:52:01.923: failed to commit changes to dconf: La connessione è chiusa
+ gsettings set org.gnome.shell.extensions.user-theme name Sierra-dark

(process:19547): dconf-WARNING **: 02:52:01.927: failed to commit changes to dconf: La connessione è chiusa
+ gsettings set org.gnome.desktop.background picture-uri file:///home//Immagini/mojave-night.jpg

(process:19551): dconf-WARNING **: 02:52:01.932: failed to commit changes to dconf: La connessione è chiusa

1
2018-06-09 00:48


Ursprung


Im Allgemeinen ist es für die Benutzeroberflächen schwierig, mit cron zu arbeiten. Verwandle es einfach in ein Skript, das dauerhaft über while Schleife, und fügen Sie sie der Startup-Anwendungsliste hinzu, damit das Skript bei der Anmeldung an der GUI automatisch gestartet wird. - Sergiy Kolodyazhnyy
Ja, ich habe bemerkt, dass ... ich habe deinen Ansatz benutzt und es hat einwandfrei funktioniert. Danke für den Tipp :) - Roberto Tortora


Antworten: