Files
SysAdminAutomation/sys_monitor.sh
jcoffey-dev 5d417f3c4c Change the copyright holder to Coffey Labs
The scripts were attributed to LINUXexpert.org, which is being retired as a
site and is no longer where this work lives. Coffey Labs is the organisation
these projects belong to.

One line per script, fifteen of them, and nothing else. LICENSE is deliberately
untouched: its "Copyright (C) <year> <name of author>" lines are GPL boilerplate
showing you how to write your own notice, and the Free Software Foundation's
own copyright on the licence text is not ours to edit.

Both git contributors are the same person, so there is no third-party copyright
here that could not be restated.
2026-08-30 01:26:45 -07:00

45 lines
1.6 KiB
Bash

#!/bin/bash
# sys_monitor.sh - System resource monitoring script
#
# Copyright (C) 2025 Coffey Labs
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Usage: sys_monitor.sh (no arguments)
# Description: Prints system uptime, memory, disk usage, and top CPU/mem processes.
set -euo pipefail
# `ps | head` is a SIGPIPE waiting to happen: head closes the pipe after
# six lines, and on a host with enough processes ps fills the buffer and
# dies with 141, which pipefail turns into a script exit. That is exactly
# the busy machine you most want this to work on, so those two pipelines
# tolerate it explicitly.
echo "==== System Uptime and Load ===="
uptime
echo -e "\n==== Memory Usage ===="
free -h
echo -e "\n==== Disk Usage ===="
# Exclude temporary filesystems (tmpfs) for clarity
df -h -x tmpfs -x devtmpfs
echo -e "\n==== Top 5 Processes by CPU Usage ===="
# Display header and top 5 CPU-consuming processes
ps -eo pid,user,comm,%cpu --sort=-%cpu | head -n 6 || true
echo -e "\n==== Top 5 Processes by Memory Usage ===="
ps -eo pid,user,comm,%mem --sort=-%mem | head -n 6 || true