Fedora 42 Updating script

Published: (December 27, 2025 at 06:18 AM EST)
5 min read
Source: Dev.to

Source: Dev.to

Overview

A comprehensive Bash script for updating the Fedora 42 operating system. It performs the following checks and actions:

  • Verifies the internet connection (required for downloading updates)
  • Ensures the script is run as root (many commands need sudo rights)
  • Checks the status of databases (MariaDB, MongoDB) and Node.js processes
  • Detects new kernel updates and evaluates available space in /boot (where DNF installs kernels)
  • Initiates the update process
  • Scans for rootkits
  • Lists installed kernels and warns if more than three are present
  • Searches for kernel errors from the last boot
  • Reports journal log size and optionally vacuums entries older than one day
  • Shows /tmp size (the systemd‑tmpfiles‑clean service cleans /tmp)
  • Displays DNF cache size and optionally clears it
  • Reports the size of /var/log

All steps are kept exactly as in the original script; only formatting and minor typographical issues have been cleaned up for better readability.

Main Script

#!/bin/bash

clear
# set -e   # Uncomment to stop the script on errors (good practice)

echo "-------------------------------------"
echo "Updates and maintenance for Fedora"
echo "-------------------------------------"

# -------------------------------------------------
# 1. System status and greeting
# -------------------------------------------------

# Check whether there is an internet connection
A=$(nmcli device status | grep eno1 | awk '{print $3}')

if [[ "$A" == "verbunden" ]]; then
    echo "✅ Internet connection available on eno1."
else
    echo "❌ NO Internet connection available, check your router."
fi

# Print the current date
DATUM=$(date +%x)
EINSCHALTZEIT=$(uptime -s | awk '{print $2}')

echo "Hallo $USER, heute ist der $DATUM. Der Rechner wurde um $EINSCHALTZEIT eingeschaltet."
echo

# Check whether we are root
BENUTZER="$USER"
if [[ "$BENUTZER" == "root" ]]; then
    echo "Ich bin Root. Starte Wartungsprozesse."

    # -------------------------------------------------
    # 🛑 NEW: Status of databases and Node.js
    # -------------------------------------------------
    echo "----------------------------------------------------"
    echo "Review of ongoing database and development processes"
    echo "----------------------------------------------------"

    # MariaDB check
    if systemctl is-active mariadb &> /dev/null; then
        echo "✅ MariaDB: Database server is running."
    else
        echo "❌ MariaDB: Database server is inactive."
    fi

    # MongoDB check
    if systemctl is-active mongod &> /dev/null; then
        echo "✅ MongoDB: Database server is running."
    else
        echo "❌ MongoDB: Database server is inactive."
    fi

    # Node.js check
    NODE_COUNT=$(pgrep node | wc -l)
    if [[ "$NODE_COUNT" -gt 0 ]]; then
        echo "⚠️ Node.js: $NODE_COUNT Node.js process(es) are currently running!"
        # List the PIDs, if needed
        pgrep node
    else
        echo "✅ Node.js: No active Node.js processes found."
    fi
    echo "----------------------------------------------------"

    # -------------------------------------------------
    # 2. Maintenance and updates
    # -------------------------------------------------
    echo "----------------------------------------------------"
    echo "Preliminary check: kernel updates & boot memory"
    echo "----------------------------------------------------"

    # 1. Check whether there is a new kernel
    KERNEL_UPDATE=$(dnf check-update kernel -q)

    if [[ -n "$KERNEL_UPDATE" ]]; then
        echo "🆕 A new kernel update has been found!"

        # 2. Check the size of /boot
        BOOT_AVAIL=$(df -m /boot --output=avail | tail -1 | tr -d ' ')

        # Safety margin: a new kernel requires approx. 150 MB (including reserve for initramfs)
        SCHWELLE=200

        echo "Verfügbarer Platz in /boot: ${BOOT_AVAIL} MB"

        if (( BOOT_AVAIL /dev/null || true

    echo "----------------------------------------------"
    echo "Kontrolle der installierten Kernel"
    # Count the installed kernel packages
    KERNEL_ANZAHL=$(rpm -q kernel | wc -l)
    echo "Aktuell sind $KERNEL_ANZAHL Kernel installiert:"
    rpm -q kernel

    # Small warning if the limit (3) is exceeded
    if (( KERNEL_ANZAHL > 3 )); then
        echo "⚠️ Hinweis: Mehr als 3 Kernel installiert. Prüfen Sie die dnf.conf!"
    fi
    echo "----------------------------------------------"

    echo "----------------------------------------------"
    # Kernel errors
    echo "Prüfung auf Kernel‑Fehler im letzten Boot‑Vorgang:"
    journalctl -kb -1 | grep -iE 'kernel panic|BUG:|oops|segfault|NMI watchdog'
    echo ----------------------------------------------"

    # Journal size check and vacuum
    echo "Prüfung Journal‑Loggröße:"
    journalctl --disk-usage

    echo "Journal‑Logfiles löschen (älter als 1 Tag)"
    journalctl --vacuum-time=1d
    echo "----------------------------------------------"

    # /tmp size check (systemd‑tmpfiles‑clean deletes the content of /tmp)
    echo "Prüfung der /tmp‑Größe:"
    du -sh /tmp
    echo ----------------------------------------------"

    # DNF cache size
    echo "Prüfung DNF‑Cache‑Größe:"
    dnf clean metadata && dnf clean packages
    du -sh /var/cache/dnf
    echo ----------------------------------------------"

    # /var/log size
    echo "Prüfung /var/log‑Größe:"
    du -sh /var/log
    echo ----------------------------------------------"

else
    echo "❌ Dieses Skript muss als root ausgeführt werden."
    exit 1
fi

All steps and checks are kept exactly as in the original script; only formatting and minor typographical issues have been cleaned up for better readability.

Additional Cleanup Steps

# delete the dnf cache
echo "DNF Cache löschen"
dnf clean packages
dnf clean metadata
dnf clean dbcache

echo "----------------------------------------------"

# checking the /tmp folder size (Kann wegen systemd-tmpfiles-clean entfernt werden, aber der Check schadet nicht)
TMP_SIZE_KB=$(du -sk /tmp/ | awk '{print $1}')
THRESHOLD_KB=400 # 400 KB

echo "Prüfung /tmp Ordnergröße"

if (( TMP_SIZE_KB > THRESHOLD_KB )); then
    echo "⚠️ Warnung: /tmp ist größer als $THRESHOLD_KB KB. Aktuelle Größe: $TMP_SIZE_KB KB"
else
    echo "✅ Die Größe von /tmp ist unter $THRESHOLD_KB KB. Aktuelle Größe: $TMP_SIZE_KB KB"
fi

echo "---------------------------------------------"

# Check DNF cache size
ORDNER_DNF="/var/cache/dnf"
SIZE_MB_DNF=$(du -sm "$ORDNER_DNF" | cut -f1)
LIMIT_MB_DNF=1024 # 1 GB

echo "Prüfung DNF Cache Größe:"
echo "Aktuelle DNF Cache Größe: $(du -sh "$ORDNER_DNF" | cut -f1)"

if [ "$SIZE_MB_DNF" -gt "$LIMIT_MB_DNF" ]; then
    echo "Achtung: Der Ordner '$ORDNER_DNF' ist größer als 1 GB."
else
    echo "✅️ Der Ordner '$ORDNER_DNF' ist unter 1 GB."
fi

echo

echo "---------------------------------------------"

# Check the size of /var/log
ORDNER_LOG="/var/log"
SIZE_MB_LOG=$(du -sm "$ORDNER_LOG" | cut -f1)
LIMIT_MB_LOG=1024 # 1 GB

echo "Prüfung /var/log Ordnergröße:"
echo "Aktuelle /var/log Größe: $(du -sh "$ORDNER_LOG" | cut -f1)"

if [ "$SIZE_MB_LOG" -gt "$LIMIT_MB_LOG" ]; then
    echo "Achtung: Der Ordner '$ORDNER_LOG' ist größer als 1 GB."
else
    echo "✅ Der Ordner '$ORDNER_LOG' ist unter 1 GB."
fi

echo

echo "----------------------------------------------"
echo

echo "Finish, Ende, an die Arbeit 💼️"

else
    echo "❌ Error: I currently do not have root privileges. The update script requires root privileges."
fi
Back to Blog

Related posts

Read more »