0

So I've essentially run into the same problem as in my other question: Running shell Script via Crontab

I will now run my shell script with systemd.timer but it is not working so far.

Here is my background.timer file:

[Unit] Description=Changes between backgrounds [Timer] OnUnitActiveSec=10s OnBootSec=10s Unit=background.service [Install] WantedBy=timers.target 

And my background.service file:

[Unit] Description=Changes between backgrounds [Service] Type=oneshot ExecStart=/home/seb/Bilder/Wallpaper/.background_skript/skript.sh 

And the file it should run:

#!/bin/bash night="$HOME/Bilder/Wallpaper/appa_night.jpg" day="$HOME/Bilder/Wallpaper/appa_day.jpg" H=$(date +%H) if [[ '13' < $H && $H < '20' ]] then gsettings set org.gnome.desktop.background picture-uri-dark file:///"$day" else gsettings set org.gnome.desktop.background picture-uri-dark file:///"$night" fi 

The bash file is also unable by myself from the terminal and my crontab had could also run it after the changes from my other question. Maby I have to do something similar in systemd?

Here is what my Crontab file looks like:

XDG_RUNTIME_DIR="/run/user/1000" 00 08 * * * systemd-run --user ~/Bilder/Wallpaper/.background_skript/skript.sh 00 20 * * * systemd-run --user ~/Bilder/Wallpaper/.background_skript/skript.sh 

So far the systemd.service don't run the bash file at all nor change the background.

2
  • It seems like you're mixing two unrelated methods – either a .timer + .service or a systemd-run cronjob, not both. What happens if you do the systemd-run... manually from a shell, with the --pty option added? (Put a set -x at the top of your script, too.) Commented Jun 2, 2023 at 8:24
  • Please add (1) what journalctl --user -u background.service says and (2) how exactly you activated the timer (systemctl --user enable --now background.timer, I suppose, but just to double-check). Who owns the script? Who is allowed to run it? Commented Jun 6, 2023 at 14:25

1 Answer 1

0

Dont call the script directly. It sounds to me like you are having permission issues. instead of calling /path/to/script.sh try infering bash with /bin/bash /path/to/script.sh

This could also be the problem for your cron issue

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.