Skip to content

u/indieross

In this archive from May 2009 to May 2023

0
posts
50
comments
0
media
118
score

Top comments

You're really looking to use After=network-online.target instead of Requires=network.target. I'd recommend putting your custom script in /usr/local/bin/ instead of /usr/bin/. And then if your system is up for a while maybe use a timer service to rerun the script every 24 hours.

  1. Create a systemd service unit file

    Let's create a service unit file. You may create a file named wallpaper.service in the /etc/systemd/system/ directory. Note that you require root privileges to do so. Use a text editor like nano or vim to create and edit the file:

    sudo nano /etc/systemd/system/wallpaper.service
    

    Paste in the following, making sure to adjust paths if necessary:

    [Unit]
    Description=Downloads the APOD and saves it as Wallpaper
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    ExecStart=/usr/local/bin/bg.sh
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    

    Save and close the file.

  2. Create a systemd timer unit file

    Now we'll create a corresponding timer for our service. Create a new file /etc/systemd/system/wallpaper.timer:

    sudo nano /etc/systemd/system/wallpaper.timer
    

    Paste in the following:

    [Unit]
    Description=Runs bg.sh every day
    
    [Timer]
    OnBootSec=0min
    OnUnitActiveSec=24h
    
    [Install]
    WantedBy=timers.target
    

    In the [Timer] section, OnBootSec=0min means the service will run immediately after the system boots. OnUnitActiveSec=24h means the service will rerun 24 hours after it was last activated.

    Save and close the file.

  3. Reload systemd daemon and enable the timer

    Next, reload the systemd daemon to make it aware of your new service and timer. Then, enable and start the timer:

    sudo systemctl daemon-reload
    sudo systemctl enable wallpaper.timer
    sudo systemctl start wallpaper.timer
    
  4. Check the status of your timer

    To make sure your timer is active and will trigger the service as expected, check its status:

    sudo systemctl status wallpaper.timer
    

That's it. Your script should now run at startup (with a delay until the network is up) and once daily.

18 points

The /usr/bin and /usr/local/bin directories are part of the Unix/Linux filesystem hierarchy, and they both serve different purposes.

  • /usr/bin: This is the primary directory of executable commands on the system. It's managed by the system's package manager (apt, yum, dnf, etc.) and should only contain binaries provided and managed by the system's package management. When you update your system, updates to programs within this directory will be handled by your package manager.

  • /usr/local/bin: This is intended for executables that are local to the machine, i.e., not part of the system's standard distribution. This includes scripts and binaries installed manually by the system administrator. This directory is usually included in a user's PATH, meaning executables here can be run directly from the command line without specifying the full path.

The main reason for keeping custom scripts in /usr/local/bin instead of /usr/bin is to avoid interfering with the system's package manager.

If you were to place your custom scripts in /usr/bin, it could potentially be erased or overwritten when you update your system. Additionally, you might unintentionally replace a system command with one of your scripts, which could cause unexpected behavior.

Placing custom scripts in /usr/local/bin helps keep them separate from system-managed binaries and reduces the risk of conflicts.

7 points

Subreddits

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.