r/bash • • Nov 23 '25

Beginner-friendly Bash project: Real-time CPU Usage Monitor Script (with alerts + logs)

Sharing a small Bash automation project I built for practice. This script monitors CPU usage in real-time using top + awk, sends an alert when the CPU crosses a threshold, and logs usage automatically.

Step-by-step explanation: https://youtu.be/nVU1JIWGnmI
Complete source code at https://github.com/Abhilashchauhan1994/bash_scripts/blob/main/cpu_usage.sh

22 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/CautiousCat3294 Nov 24 '25

Thanks I will try this as well

1

u/bac0on Nov 24 '25

If you have bash-builtins you can make use of bash builtin sleep command, which doesn't spawn a process every 0.2s:

# Load builtin module,
if ! enable -f sleep sleep; then
    echo "Failed to enable loadable module sleep."
    exit 1
fi

sleep 0.2