나는 Linux Mint에서 10분마다 배경 이미지를 전환해야 하는 다음 crontab 작업을 작성했습니다.
*/10 * * * * /home/me/Pictures/wallpapers/switcher.sh >> /home/me/Logs/wallpaper.log 2>&1
이 쉘 스크립트를 호출합니다.
#!/bin/bash
gsettings set org.cinnamon.desktop.background picture-uri $(/usr/bin/python3 /home/me/Pictures/wallpapers/spaceBack.py)
로그 파일에 다음 오류 메시지가 나타납니다.
(process:18951): dconf-CRITICAL **: 14:00:02.264: unable to create file '/home/me/.cache/dconf/user': Permission denied. dconf will not work properly.
(process:18951): dconf-CRITICAL **: 14:00:02.265: unable to create file '/home/me/.cache/dconf/user': Permission denied. dconf will not work properly.
(process:18951): dconf-CRITICAL **: 14:00:02.265: unable to create file '/home/me/.cache/dconf/user': Permission denied. dconf will not work properly.
(process:18951): dconf-WARNING **: 14:00:02.265: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
쉘을 통해 스크립트를 실행할 때만 이 오류가 발생합니다 cron
(터미널을 통해 제대로 실행됩니다).
전화 ls -la /home/me/.cache/dconf/
반환
drwx------ 2 root root 4096 Jul 6 16:13 .
drwx------ 48 me me 4096 Jun 29 15:33 ..
-rw------- 1 root root 2 Jul 6 16:13 user
답변1
DBUS_SESSION_BUS_ADDRESS
환경 변수로 설정해야 합니다. 이 질문에서 가져온 다음 스크립트를 통해 올바른 값을 설정할 수 있습니다.원격 쉘을 통해 Gsettings를 변경하는 방법은 무엇입니까?
#!/bin/bash
# Remember to run this script using the command "source ./filename.sh"
# Search these processes for the session variable
# (they are run as the current user and have the DBUS session variable set)
compatiblePrograms=( nautilus kdeinit kded4 pulseaudio trackerd )
# Attempt to get a program pid
for index in ${compatiblePrograms[@]}; do
PID=$(pidof -s ${index})
if [[ "${PID}" != "" ]]; then
break
fi
done
if [[ "${PID}" == "" ]]; then
echo "Could not detect active login session"
return 1
fi
QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "${QUERY_ENVIRON}" != "" ]]; then
export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
echo "Connected to session:"
echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"
else
echo "Could not find dbus session ID in user environment."
return 1
fi
return 0
그런 다음 cron 작업을 다음과 같이 수정할 수 있습니다.*/10 * * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /home/me/Pictures/wallpapers/switcher.sh >> /home/me/Logs/wallpaper.log 2>&1