Module 1 · Project 01 · Linux Server Automation Toolkit · Lesson 2 of 48
Your first health-check script
Read CPU, memory, disk, processes and services from the command line, then bundle the checks into one Bash script.
In this lesson · about 25 minutes
- Use uptime, df, free, top, ps and systemctl to read a server's health
- Explain load average and why a full disk is dangerous
- Write, make executable and run a Bash health-check script
The problem
Imagine you look after a handful of servers. Every morning you log in to each one with SSH and type the same commands to see if anything is wrong. It is slow, easy to forget, and you only notice problems when you happen to look. Project 01 fixes that, one script at a time.
The commands that tell you how a server feels
| Question | Command | What to look at |
|---|---|---|
| How busy is the CPU? | uptime, top -bn1 | Load average; the %Cpu line and the top processes |
| Is memory running out? | free -h | The available column, not "free" |
| Is the disk filling up? | df -h | Use% for / |
| What is running? | ps aux --sort=-%cpu | head | Which process uses the most CPU or memory |
| Is the web server up? | systemctl is-active nginx | active or not |
The load average is three numbers: the average number of processes running or waiting for the CPU over the last 1, 5 and 15 minutes. Compare it with the number of CPU cores (nproc): on a 2-core server, a load of 2.0 means fully busy, and 6.0 means work is queuing up.
A full disk is one of the most common causes of outages: databases stop writing, logs stop, and apps crash in strange ways. That is why disk usage is in every health check.
Try it · watch it run
A live server and the commands that read it
This server is live (in simulation). Start a CPU-heavy job, a memory leak or a log flood, then run the commands on the right and see how each one reveals the problem.
web-01
nginx runningCause trouble
Run a command
deploy@web-01:~$ uptime
10:18:07 up 12 days, 3:18, 1 user, load average: 0.28, 0.30, 0.29
# 2 CPU cores, so a load near 2.00 means both cores are busy.Whiteboard · watch and try
Reading a load average
Press Play to see how to tell whether a load average is a problem.
Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.
Turn the commands into a script
A Bash script is just a text file of commands. Put them together once, and you never type them again:
#!/bin/bash
# health-check.sh: a quick look at this server's health
echo "== Server health check: $(hostname) at $(date) =="
echo "-- Uptime and load --"
uptime
echo "-- Disk --"
df -h /
echo "-- Memory --"
free -h
echo "-- Top processes by CPU --"
ps aux --sort=-%cpu | head -n 6
echo "-- nginx --"
systemctl is-active nginx
#!/bin/bash, the shebang, tells Linux which program runs the file.- Lines starting with
#are comments for humans. $(hostname)runs a command and drops its output into the text.- Before you can run it, make it executable:
chmod +x health-check.sh. Then run it with./health-check.sh.
Hands-on lab (simulated terminal)
Lab: write and run health-check.sh
A practice server with the script already typed into scripts/health-check.sh. Follow the steps. Nothing here touches a real machine.
Step 1 of 5. Type each command and press Enter. Nothing runs on your computer.
1. Look at the script with cat.
Sorting drill
Which command answers it?
Put each question under the command you would run first.
- Users say uploads fail with 'No space left on device'
- The app was killed and the kernel log mentions OOM
- Every page is slow and the fans are loud
- The website returns 'connection refused'
- Is log rotation keeping /var under control?
- Did the database service start after the reboot?
0 of 6 sorted
Check your understanding0 of 3 correct
Key terms
Say the meaning to yourself, then tap a card to check.
Quiz score: 0 of 3
Written by Noviq Academy in its own words. The labs are simulations: no real servers are touched. When you build the projects yourself, use a practice virtual machine or a free-tier cloud account you control, watch your cloud spending, and never run cleanup or delete commands on a machine you care about. Tool names belong to their owners; versions and output are shown for learning and may differ slightly from yours. Read-aloud and the whiteboard voice use your device's built-in voices.