0

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[1]: Started Fetch random picture from unsplash.
déc. 19 13:21:24 localhost.localdomain systemd[1728]: fetch_unsplash.service: Failed to execute command: Permission denied
déc. 19 13:21:24 localhost.localdomain systemd[1728]: 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[1]: fetch_unsplash.service: Main process exited, code=exited, status=203/EXEC
déc. 19 13:21:24 localhost.localdomain systemd[1]: 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)?

  • Can you show the permissions for that script, because systemd disagrees with you: Failed at step EXEC spawning /home/nicolas/.local/bin/fetch_unsplash_1920x1080: Permission denied. Also, is your /home filesystem mounted with the noexec flag? Check the filesystem you're on with df /home/nicolas/.local/bin/fetch_unsplash_1920x1080 followed by mount | grep ... that filesystem – Jeff Schaller Dec 19 '18 at 17:37
  • The script has the permission -rwxr-xr-x, the filesystem where the script is located is not mounted with noexec. Also the location where the script is trying to write is not on the same partition and it has the same mount options. – Nicolas Scotto Di Perto Dec 20 '18 at 17:38
  • My only other thought was that (if /home is indeed a separate filesystem), that it's not mounted when this unit tries to execute; seems rather unlikely, given the After=network-online.target, but thought I'd mention it, just in case. – Jeff Schaller Dec 20 '18 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.