Last Updated: May 22nd, 2026

Automatically Downloading, Installing and Cleaning System

Introduction:

In a home lab environment, one key feature of is programming the server to be autonomous. As in, menial tasks such as updating the system with the latest and greatest security patches and application versions is imperative. One of the best ways to do this is to write a program that will aid in applying the updates automatically. It also paramount to consider cleaning the system of older versions of depreciated software or packages to have an optimized system performance. There is no utility in having older versions of the kernel or program versions lurking around and taking up space.

Objective:

It is to provide a code and commands in order to augment the process of the server being fully automatic.

Installation:

For simplicity the commands and code should be copy and paste. Screenshots be will provided in order to aid in walking you through the process. This tutorial is based upon Fedora Linux install. Commands provided in this tutorial will be nuanced in comparison to other Operating Systems.

  1. Open the terminal
  2. Create a directory to store all of you code on the server. When running a server it is imperative to think about implementing and augmenting organization strategies through out the server especially for continual accessibility of programs or applications.
  3. mkdir Programs && cd Programs

    This command will create the folder and then “cd” means to "change directory." You will now in the folder.

  4. Now, we will create a file using nano text editor and the code will provided below and you can just copy and paste it into the file. The name of the file could be whatever your preference is, but for this tutorial it will be called “automated_upgrades.sh.” Make sure to be in the Programs directory prior typing in the command below.
  5. sudo nano automated_upgrades.sh

    You will be prompted to type in your password and press enter then terminal show a blank file. It’s name is "automated_upgrades.sh" which is at the top center of terminal window.

    Copy and paste the code below to the file.

              
    #!/bin/bash
    
    # Update package list
    dnf check-update
    
    # List outdated packages (optionally)
    outdated_packages=$(dnf repoquery --installed --latest-limit=1)
    
    if [ -n "$outdated_packages" ]; then
      # Remove outdated packages
      dnf remove $(dnf repoquery --installed --latest-limit=1)
    else
      echo "No outdated packages found."
    fi
              
          

    Press "ctrl + X" to exit out of the file on the keyboard. You will be prompted to save the file by press "y" for yes. Then press "enter" key on the keyboard to confirm the name of the file.

  6. The file has been saved, but it needs to be setup as an executable program. At this point the code, is just a file. It needs a executable permission given to the file in order for it be activated. By typing in the command below, we can see the file has read and write permissions, but not executable permission. We will need to change it.
  7. ls -l

    Type in the command below to give the file permission to be executable.

    sudo chmod +x ~/Programs/automated_upgrades.sh && ls -l

    You may be prompted to type in your password then press “Enter”

  8. Now we will need to create and register a service and timer automate the process through systemd. We will need to change directories as well. Using the command provided below, it will change directories and create a new file which will be the service file.
  9. cd /etc/systemd/system && sudo nano automated_updates.service

    Password may be required and press "Enter," then nano editor will show a blank file. The name of the file is "automated_updates.service"

    Now, copy and paste the setting conditions below:

                  
    [Unit]
    Description=Cleanup outdated packages
    
    [Service]
    Type=simple 
    User=root 
    Group=root 
    ExecStart= /home/**user/Programs/automated_upgrades.sh   
                  
                

    The double asterisks (**) means to change this to your username.

    Press "ctrl + X" to exit, then press "y" for yes. Confirm the name of the file by pressing "enter."

  10. The timer file need to be created so type in the command below with the file name being "automated_updates.timer."
  11. sudo nano automated_updates.timer

    You will be prompted for you password and press "Enter." Copy and paste the contents below into the timer file.

                
    [Unit]
    Description=Run automatic_updates.sh every day
    
    [Timer]
    OnBootSec=10min
    OnUnitActiveSec=30d
    Unit=automated_updates.service
    
    [Install]
    WantedBy=timers.target
                
             

    Press "ctrl + X" to exit, then press "y" for yes. Confirm the name of the file by pressing "enter."

  12. The timer file has been created, it is time to start and enable the service. Type in the command below:
  13. sudo systemctl start automated_updates.timer && sudo systemctl enable automated_updates.timer

    Type in your password if prompted and press "enter."

  14. The timer and service is now registered with systemd, but the affects will have happen when system restarts, it can be negated by initializing the timer and service now. We need to type in the command below to restart the systemd.
  15. sudo systemctl daemon-reload

    Type in your password if prompted and press "enter."

    If there is not any feedback, then the command was successfully executed.

  16. To confirm the status of the timer, we will need to type the command below followed by typing in your password if prompted and pressing "enter."
  17. sudo systemctl status automated_updates.timer

    The command should pull something fairly equivalent in the photo above. The key indicators is seeing the word active in a green font color in conjunction with the word “enabled” being in a green font color. This confirms the system is active and will run when it is time appropriate. The system updates will be applied upon next initialization.