I would like to fetch a random picture from unsplash in
/usr/share/wallpapers each time I reboot my laptop.
I wrote this service as a first try:
[Unit] Description=Fetch random picture from unsplash After=network-online.target [Service] User=root Type=idle ExecStart=/home/nicolas/.local/bin/fetch_unsplash_1920x1080 [Install] WantedBy=network-online.target
I enabled it, reboot and I see it fails because:
déc. 19 13:21:24 localhost.localdomain systemd: Started Fetch random picture from unsplash. déc. 19 13:21:24 localhost.localdomain systemd: fetch_unsplash.service: Failed to execute command: Permission denied déc. 19 13:21:24 localhost.localdomain systemd: fetch_unsplash.service: Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied déc. 19 13:21:24 localhost.localdomain systemd: fetch_unsplash.service: Main process exited, code=exited, status=203/EXEC déc. 19 13:21:24 localhost.localdomain systemd: fetch_unsplash.service: Failed with result 'exit-code'. ~
The path for the script is correct and the script has execution permission.
Here is code (it's also a base for future improvements):
#!/usr/bin/bash location="$1" if [ -z "$location" ] then location="/usr/share/wallpapers" fi name="random_unsplash_1920x1080.jpg" wget -q "https://picsum.photos/1920/1080/?random" --output-document "$location/$name"
So what does not work?
Also this raises two problems for me: how to give permission to the service for writing in
/usr/share/wallpapers? And how to get the service start only when the laptop is truly connected to internet (am I doing it right in this service)?