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.
-
awkis 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
$7inawk '{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