Mini project
Linux Server Health Monitor with Bash
A Bash script that checks disk, memory, CPU load and important services every five minutes with cron, logs the results, raises alerts when limits are crossed, and builds a daily report.
Bashcrondf, free, ps, systemctlawkcurl
The problem
Servers fail quietly: a disk fills up, memory runs out or a service stops, and nobody notices until a website goes down. System administrators and DevOps engineers write small monitoring scripts to catch these problems early. This project builds one with the tools every Linux machine already has.
Features to build
- Check disk usage of each mounted file system with df
- Check memory and swap with free, using the 'available' column
- Read the 1, 5 and 15 minute load averages and compare them with the number of CPU cores
- Check that chosen services, for example ssh and nginx, are running with systemctl
- List the top 5 processes by CPU and by memory
- Read limits from a config file and log OK, WARNING or CRITICAL lines with timestamps
- Send an alert through a webhook with curl when a check turns critical, at most once an hour per problem
- Run every 5 minutes with cron, and build a daily summary report
Build plan
- 1
Start the script safely
Begin with #!/usr/bin/env bash and set -euo pipefail, quote every variable, and load limits from a config file.
- 2
Write one function per check
Each check function prints a status line and returns an exit code: 0 for OK, 1 for warning and 2 for critical.
- 3
Parse command output
Use awk to pull the numbers out of df, free and /proc/loadavg, and compare them with the limits.
- 4
Log and alert
Append each result with a timestamp to a log file. Store the time of the last alert for each check, so the same problem does not send alerts every 5 minutes.
- 5
Schedule and report
Add a crontab entry such as */5 * * * * to run the checks, and a daily entry that summarises the log with awk into a report.
Learn these first
Each part of the project is taught in one of these free lessons.
- Bash Scripting Tutorial: Write Your First Shell Script
- Bash Variables and Quoting Explained
- Bash if Statements: Conditions, test and case
- Bash Functions: Arguments, local and Return Values
- Bash Script Arguments and Exit Codes Explained
- Linux Disk Space: df, du and Finding Large Files
- Linux Processes: ps, top, kill and Background Jobs
- systemd and systemctl Tutorial: Manage Linux Services and Logs
- Linux awk Tutorial: Columns, Filters and Totals
- Linux cron Tutorial: Schedule Jobs with crontab
- curl Tutorial: Call APIs and Download Files from the Terminal
- Writing Safe Bash Scripts: set -euo pipefail, trap and ShellCheck
- Bash Project: Analyse a Web Server Log
Make it stand out
- An HTML report with simple bar charts made in plain HTML and CSS
- Check that a list of websites respond with HTTP 200 and record response times
- Rotate the log files with logrotate
- Package it as a systemd timer instead of cron
Viva and interview questions
Try to answer each one aloud before you open it.
What does the load average mean?
The average number of processes that were running or waiting to run over the last 1, 5 and 15 minutes. On Linux it also counts processes waiting for disk. Compare it with the number of CPU cores: a load of 4 on a 4-core machine means it is fully busy.
Why use the 'available' memory column instead of 'free'?
Linux uses spare memory as disk cache, so 'free' often looks very low even on a healthy machine. 'available' estimates how much memory programs can still use, including cache that can be released.
What does set -euo pipefail do?
-e stops the script when a command fails, -u treats unset variables as errors, and -o pipefail makes a pipeline fail if any command in it fails, not just the last one. Together they stop scripts from carrying on with bad data.
What does */5 * * * * mean in a crontab?
Run every 5 minutes, every hour, every day of the month, every month and every day of the week. The five fields are minute, hour, day of month, month and day of week.
Why limit how often alerts are sent?
Without a limit, a full disk would send an alert every 5 minutes until fixed. People then start ignoring alerts, which is dangerous. Sending one alert, then a reminder later, keeps alerts useful.
What to put in your project report
- Abstract: the problem, your solution and the result in one paragraph.
- Introduction and problem statement: who has the problem and why it matters.
- Requirements: the features (functional) and qualities such as speed and security (non-functional).
- Design: architecture diagram, database tables or data flow, and screen layouts.
- Implementation: the main modules and the most interesting code, explained.
- Testing: the test cases you ran, with inputs, expected and actual results.
- Results: screenshots or numbers that show the project working.
- Conclusion and future scope: what you achieved and what you would add next.
Your college may give its own format. Follow that first, and use this list to check nothing is missing.