Skip to content
Laviyx Learn

Try

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.

Intermediate 1–2 weeks 1 studentUpdated

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. 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. 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. 3

    Parse command output

    Use awk to pull the numbers out of df, free and /proc/loadavg, and compare them with the limits.

  4. 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. 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.

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

  1. Abstract: the problem, your solution and the result in one paragraph.
  2. Introduction and problem statement: who has the problem and why it matters.
  3. Requirements: the features (functional) and qualities such as speed and security (non-functional).
  4. Design: architecture diagram, database tables or data flow, and screen layouts.
  5. Implementation: the main modules and the most interesting code, explained.
  6. Testing: the test cases you ran, with inputs, expected and actual results.
  7. Results: screenshots or numbers that show the project working.
  8. 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.