How to Set Up a Monitoring Script with bash
A bash health script gives fast visibility without Grafana. Run it by hand or via cron to keep snapshots.
Steps
Create the summary script:
Blog
Hands-on tutorials on Linux, security, networking, and game servers, written so you can follow along step by step.
A bash health script gives fast visibility without Grafana. Run it by hand or via cron to keep snapshots.
Create the summary script:
Email alerts catch problems before users do. A small script plus cron covers basic thresholds without a full monitoring stack.
Install a local mail client (configure SMTP/relay for your provider):
sudo apt updatesudo apt install -y mailutilsCreate a script that emails when root disk exceeds 85%:
rsyslog collects system and application syslog messages. On a VPS it is the base layer before alerts or a SIEM.
Install and start rsyslog:
sudo apt updatesudo apt install -y rsyslogsudo systemctl enable --now rsyslogsystemctl status rsyslog --no-pagerA Failover (floating/additional) IP lets you move a service between hosts. On modern Ubuntu you declare it in netplan.
List interfaces and current netplan config:
ip -br addrls /etc/netplan/sudo cat /etc/netplan/*.yamlAdd the extra IP on the primary NIC (example — replace names/addresses):
Hugo builds blazing-fast static HTML. On a VPS it fits blogs and landings with no PHP or database.
Install Hugo (distro package; use the official .deb for newest):
sudo apt updatesudo apt install -y hugohugo versionCreate the site and a sample post:
cdu is an interactive du: it sorts folders by size so you quickly see what eats the disk before deleting blindly.
Install ncdu:
sudo apt updatesudo apt install -y ncduScan the filesystem (start at / or a specific mount):
sudo ncdu -x /etstat lists sockets and connections. On recent Ubuntu the recommended tool is ss (from iproute2); both show which ports are open.
Install net-tools (netstat) if you need it; ss is usually already there:
sudo apt updatesudo apt install -y net-tools iproute2TCP/UDP listeners with netstat:
lsof (list open files) shows which process holds a file or a port. Perfect when a service fails to start because the port is already taken.
Install lsof:
sudo apt updatesudo apt install -y lsofWho is listening on port 80?
sudo lsof -iTCP:80 -sTCP:LISTENgrep finds lines that match a pattern. It is the fast way to hunt errors in logs without opening the whole file.
On Ubuntu it is usually installed. If missing:
sudo apt updatesudo apt install -y grepSearch a string in a log (line numbers, ignore case):
grep -ni "error" /var/log/nginx/error.logwget and curl fetch files and talk to APIs from the shell. On a VPS you will use them for ISOs, scripts, health checks and HTTP debugging.
Install both tools (Ubuntu/Debian):
sudo apt updatesudo apt install -y wget curlDownload a file with wget (follows redirects, shows progress):