💀 I built a full system monitor in Bash — and fought awk along the way

I wanted to see how far I could push pure Bash before it collapses under its own syntax.
So, naturally, I decided to write a system monitoring tool — in Bash.
And thus, system-monitor was born:
👉 GitHub repo

Yes, it’s fully functional. Yes, it uses …


This content originally appeared on DEV Community and was authored by DanLin

I wanted to see how far I could push pure Bash before it collapses under its own syntax.
So, naturally, I decided to write a system monitoring tool — in Bash.
And thus, system-monitor was born:
👉 GitHub repo

Yes, it’s fully functional. Yes, it uses colors. Yes, awk is involved.

No, I don’t recommend doing this sober. 😅

💡 The idea

I wanted a single script that could show:

  • CPU load and number of cores
  • RAM usage and percentage
  • Disk space for /
  • Network I/O
  • Process count Basically, the “lazy Linux admin toolkit” in one file. Something like this:
./system-monitor.sh

and boom — everything you’d usually get from top, free, df, and ip combined.

⚙️ The features

What started as a 10-line script turned into a 250+ line CLI tool with:

  • Command-line arguments (--help, --brief, --no-color, --version, -i N)
  • Colorized output for warnings/critical thresholds
  • Continuous monitoring mode
  • Safe shutdown with signal trapping (Ctrl+C)
  • Brief (machine-readable) mode for piping into other scripts
  • Dependency checks and graceful error handling

Example:

./system-monitor.sh -i 5 --no-color

Updates every 5 seconds without colors.
Press Ctrl+C to stop — yes, it even says goodbye politely.

🧩 Some code highlights

Color management:

RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m'

Because monitoring your system is serious business — but who doesn’t love a bit of RGB?

Load detection magic:

CPU_LOAD_1MIN=$(cat /proc/loadavg | awk '{print $1}')
CPU_CORES=$(nproc)
load_percent=$(echo "scale=0; ($CPU_LOAD_1MIN * 100) / $CPU_CORES" | bc)

That moment when you realize you’re using awk, bc, and /proc in one line and it actually works.

Network metrics:

interface=$(ip route get 8.8.8.8 | awk '{print $5}' | head -1)
rx=$(cat /sys/class/net/$interface/statistics/rx_bytes)
tx=$(cat /sys/class/net/$interface/statistics/tx_bytes)

I like to imagine Bash crying softly every time it runs this.

🧠 What I learned

  • Bash can do a lot — if you’re patient (and slightly masochistic).
  • Quoting is a survival skill. Forget one and you’re debugging for hours.
  • awk is an ancient curse. It always works, but never for the reason you expect.
  • Color helps debugging. Visual feedback saves your sanity.
  • Document your code. Because 3 a.m. you will have no clue what that $7 in awk '{print $7}' was.

🧰 The brief mode

I added a --brief flag that outputs all metrics in a machine-readable format — perfect for logging or Prometheus-style integration.

./system-monitor.sh --brief

Output:

timestamp=1730765432
cpu_load_percent=12
mem_usage_percent=43.5
disk_usage_percent=56
network_rx_mb=12.4
process_count=187

Basically, JSON for people who hate themselves.

🧯 Safety first: signal handling

If you hit Ctrl+C, it doesn’t just die — it politely says goodbye:

trap cleanup INT TERM

cleanup() {
    echo -e "\nMonitoring stopped. Goodbye!"
    exit 0
}

Because professionalism.

🚀 AUR packaging

After testing it on Arch, I thought — why not go all in?
So I wrote a PKGBUILD, threw it into the AUR, and now you can literally install it with:

yay -S system-monitor

And that’s the moment I realized:

“Oh no. I’ve become that guy who writes Bash utilities for other people.”

🧭 Final thoughts

Was this efficient? Probably not.
Did I learn a lot? Absolutely.

Here’s what I got from it:

  • Deep understanding of Bash syntax and traps
  • Practical use of /proc and awk
  • Appreciation for proper CLI design
  • And a newfound respect for people who don’t do this in Bash

If you’re thinking of writing your first utility — do it.
Even if it’s messy. Even if awk haunts your dreams.

Because once you see your tool working, it’s worth every headache.

🔗 Links

🐧 GitHub: https://github.com/DanLinX2004X/system-monitor

📦 AUR: https://aur.archlinux.org/packages/system-monitor


This content originally appeared on DEV Community and was authored by DanLin


Print Share Comment Cite Upload Translate Updates
APA

DanLin | Sciencx (2025-11-04T21:16:25+00:00) 💀 I built a full system monitor in Bash — and fought awk along the way. Retrieved from https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/

MLA
" » 💀 I built a full system monitor in Bash — and fought awk along the way." DanLin | Sciencx - Tuesday November 4, 2025, https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/
HARVARD
DanLin | Sciencx Tuesday November 4, 2025 » 💀 I built a full system monitor in Bash — and fought awk along the way., viewed ,<https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/>
VANCOUVER
DanLin | Sciencx - » 💀 I built a full system monitor in Bash — and fought awk along the way. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/
CHICAGO
" » 💀 I built a full system monitor in Bash — and fought awk along the way." DanLin | Sciencx - Accessed . https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/
IEEE
" » 💀 I built a full system monitor in Bash — and fought awk along the way." DanLin | Sciencx [Online]. Available: https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/. [Accessed: ]
rf:citation
» 💀 I built a full system monitor in Bash — and fought awk along the way | DanLin | Sciencx | https://www.scien.cx/2025/11/04/%f0%9f%92%80-i-built-a-full-system-monitor-in-bash-and-fought-awk-along-the-way/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.