Почему я получаю ошибки в этом сценарии?

Я в настоящее время пытаюсь реализовать этот сценарий, данный как принятый ответ по этому вопросу. Теперь я создал сценарий change_wallpaper_reddit.sh, и сценарий ниже для Вашего удобства.

# Reference: https://askubuntu.com/a/911958/566421

# Set the script home directory:
SHOME=Daily-Reddit-Wallpaper

# Set the output folder in the home directory to save the Wallpapers to:
DIR=Pictures/Wallpapers

# Set the --time parameter value
TIME=now

# Check if the Desktop Environment is changed:
LAST=$(cat "$HOME/$SHOME/last-desktop-environment.log")
if [ "$1" != "$LAST" ]
then
    # Get the name of the last saved wallpaper image:
    IMG=$(ls -Art $HOME/$DIR | tail -n 1)
    rm $HOME/$DIR/$IMG
fi

# Desktop Environment cases:
if [ -z ${1+x} ] || [ "$1" = "gnome" ] || [ "$1" = "unity" ]
then
    # Set the necessary environment variables - PID=$(pgrep gnome-session -u $USER) - UBUNTU/UNITY/GNOME:
    export GNOME_DESKTOP_SESSION_ID=true
    export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep gnome-session -n)/environ | cut -d= -f2-)

    # Run the script:
    ~/$SHOME/change_wallpaper_reddit.py --time $TIME --output ~/$DIR 

elif [ "$1" = "kde" ]
then
    # Set the necessary environment variables - KUBUNTU/PLASMA/KDE:
    export KDE_FULL_SESSION=true
    export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep startkde -n)/environ | cut -d= -f2-)

    # Run the script:
    $HOME/$SHOME/change_wallpaper_reddit.py --time $TIME --output $DIR

elif [ "$1" = "mate" ]
then
    # Set the necessary environment variables - Ubuntu MATE/MATE:
    export DESKTOP_SESSION=mate
    export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep mate-session -n)/environ | cut -d= -f2-)

    # Run the script:
    $HOME/$SHOME/change_wallpaper_reddit.py --time $TIME --output $DIR

elif [ "$1" = "lxde" ]
then
    # Set the necessary environment variables - type 'echo $DISPLAY` to find your current display - LUBUNTU/LXDE:
    export DESKTOP_SESSION=Lubuntu
    export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep lxsession -n)/environ | cut -d= -f2-)
    export DISPLAY=:1.0

    # Run the script:
    $HOME/$SHOME/change_wallpaper_reddit.py --time $TIME --output $DIR

elif [ "$1" = "xfce4" ]
then
    # Set the necessary environment variables - XUBUNTU/XFCE4:
    export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep xfce4-session -n)/environ|cut -d= -f2-)

    # Run the script:
    $HOME/$SHOME/change_wallpaper_reddit.py --time $TIME --output $DIR

    # Get the name of the last saved wallpaper image:
    IMG=$(ls -Art $HOME/$DIR | tail -n 1)

    # Since 'change_wallpaper_reddit.py' doesn't work properly with xfce4 we shall set the background manually:
    xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/last-image --set $HOME/$DIR/$IMG

    # Property list:      xfconf-query --channel xfce4-desktop --list
    # Current settings:   xfconf-query -c xfce4-desktop -p /backdrop -lv
    # Set 'zoomed' style: xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/image-style --set 5
    # References:         https://askubuntu.com/q/380550/566421 and https://askubuntu.com/q/414422/566421

else
    echo "Wrong argument. It must be:"
    echo "  - empty (default) = gnome = unity"
    echo "  - kde"
    echo "  - lxde"
    echo "  - mate"
    echo "  - xfce4"
fi

# Save the current value of the Desktop Environment variable:
echo "$1" > "$HOME/$SHOME/last-desktop-environment.log"

Я создал новое задание в моем sudo crontab, как показано ниже:

0 * * * * /home/sharan/Daily-Reddit-Wallpaper/change_wallpaper_reddit.sh gnome > /home/sharan/Daily-Reddit-Wallpaper/cron.log 2>&1

Однако этот сценарий не работает и дает мне ошибки ниже, в cron.log файл.

cat: /root/Daily-Reddit-Wallpaper/last-desktop-environment.log: No such file or directory
ls: cannot access '/root/Pictures/Wallpapers': No such file or directory
rm: cannot remove '/root/Pictures/Wallpapers/': No such file or directory
/home/sharan/Daily-Reddit-Wallpaper/change_wallpaper_reddit.sh: 29: /home/sharan/Daily-Reddit-Wallpaper/change_wallpaper_reddit.sh: /root/Daily-Reddit-Wallpaper/change_wallpaper_reddit.py: not found
/home/sharan/Daily-Reddit-Wallpaper/change_wallpaper_reddit.sh: 88: /home/sharan/Daily-Reddit-Wallpaper/change_wallpaper_reddit.sh: cannot create /root/Daily-Reddit-Wallpaper/last-desktop-environment.log: Directory nonexistent

Я точно не понимаю то, что идет не так, как надо здесь.

0
задан 31 May 2017 в 05:06

1 ответ

Вы выполняете задание крона как корень, ожидая работать в рамках корневого каталога пользователя. Проблема видима в этой строке:

LAST=$(cat "$HOME/$SHOME/last-desktop-environment.log")

, где $HOME переводится в /root/ и $SHOME к Daily-Reddit-Wallpaper. Затем cat жалуется, что нет никакого файла /root/Daily-Reddit-Wallpaler/last-desktop-environment.log.

3
ответ дан 3 November 2019 в 04:07

Другие вопросы по тегам:

Похожие вопросы: