Por que estou recebendo erros neste script?

0

No momento, estou tentando implementar esse script como a resposta aceita em isso change_wallpaper_reddit.sh e o script está abaixo para sua conveniência.

# 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://sobrelinux.info/questions/19093/xubuntu-how-to-set-the-wallpaper-using-the-command-line"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"

Eu criei um novo trabalho no meu sudo crontab , conforme mostrado abaixo:

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

No entanto, esse script não está funcionando e fornece os erros abaixo, no arquivo 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

Eu não entendo exatamente o que está errado aqui.

    
por Sharan Duggirala 31.05.2017 / 14:06

1 resposta

3

Você executa a tarefa cron como raiz, enquanto espera trabalhar no diretório inicial de um usuário. O problema é visível nesta linha:

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

em que $HOME é traduzido para /root/ e $SHOME para Daily-Reddit-Wallpaper . Então cat reclama que não há arquivo /root/Daily-Reddit-Wallpaler/last-desktop-environment.log .

    
por Jos 31.05.2017 / 14:11