Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

BashbeginnerdevopsAI generated

System Resource Snapshot Reporter

Write a Bash script that takes a snapshot of a Linux machine's health at this moment: CPU usage, memory usage, disk usage per filesystem, and the processes using the most CPU and memory. It prints everything as a neat text report, and with --html it produces a simple web page you can open in a browser or share. It reads information straight from the /proc filesystem and from standard tools like df, free and ps. You'll learn how Linux exposes system information, how to extract numbers from command output with awk, how to do arithmetic in Bash, and how to format clean, readable output.

Estimate
~8h
Steps
7
Completed by
0
Proposed by
codeseed.app

/proc filesystem · awk · df · free

Project roadmap

  1. 01

    Set up the script

    ~1h

    Create snapshot.sh starting with #!/usr/bin/env bash and set -euo pipefail. Add a usage function and options: --html (write an HTML report), -o FILE (the output file, default snapshot.html) and --disk-threshold N (default 80). Check that it's running on Linux (by testing that /proc/stat exists) and exit with a clear message otherwise. Done when: ./snapshot.sh --help prints the usage.

  2. 02

    Measure CPU and memory

    ~1.5h

    Read the first line of /proc/stat twice, one second apart, and calculate CPU usage as the percentage of non-idle time between the two readings. Read /proc/meminfo with awk to get MemTotal and MemAvailable, and calculate used memory in MB and as a percentage. Also show the load averages from /proc/loadavg. Done when: the script prints CPU %, memory used and total, and the load averages, with values close to what top shows.

  3. 03

    Measure disk usage

    ~1h

    Run df -P and use awk to list each real filesystem (skipping tmpfs, devtmpfs and similar) with its mount point, size, used space and use percentage. Mark filesystems at or above the --disk-threshold with a ! sign. Done when: the disk section lists every real filesystem and marks the full ones.

  4. 04

    List the top processes

    ~1h

    Use ps -eo pid,user,pcpu,pmem,comm --sort=-pcpu to list the 5 processes using the most CPU, and the same with --sort=-pmem for memory. Cut long process names so the columns stay aligned. Done when: both top-5 lists are printed with aligned columns.

  5. 05

    Print the text report

    ~1h

    Put the sections together into one report with a header containing the host name, date and uptime, then CPU and memory, disks, and top processes, each under a clear heading. Use printf for aligned columns. Done when: running the script prints a tidy, readable report.

  6. 06

    Add HTML output

    ~1.5h

    With --html, write the same data to an HTML file with a <table> for each section and a small inline <style> block, highlighting disks over the threshold in red. Escape special characters (&, <, >) in process names so they can't break the page. Done when: the generated file opens in a browser and shows all sections correctly.

  7. 07

    Check it with ShellCheck

    ~1h

    Run shellcheck snapshot.sh and fix every warning. In the README, show an example text report and explain how to schedule a snapshot every hour with cron. Done when: shellcheck reports no issues and the README contains the example and cron instructions.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~8h · 7 steps

Tech stack

/proc filesystemawkdffree