Capstone project

Capstone: a server health check

Lesson 20 of 20 · 20 min · Module 6: Networking from the shell

Put it all together. You are on call and need a short, reliable health report for the server. Build it entirely from commands, so it can be repeated tomorrow.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Combine system, log, and network checks
  • Build a file from command output
  • Make a repeatable, private report

The idea

Combine what you know: hostname, grep -c, ss, curl, redirection, and permissions. echo -n "text" prints text without a line break, so the next command’s output continues on the same line.

echo -n "User: " > who.txt
whoami >> who.txt
cat who.txt

01Labels and values

echo -n "Errors: " starts a line without finishing it. The next command, grep -c ERROR logs/app.log >> file, writes 3 and a line break. Together they produce Errors: 3.

echo -n "Errors: " > x.txt
grep -c ERROR logs/app.log >> x.txt
cat x.txt
Output
Errors: 3

02Count with a pipe

ss -tln lists listening TCP ports. Piping it into grep -c ":8080" counts the lines that mention port 8080: 1 means the app is listening.

03Why commands instead of typed values

A report built from commands stays correct tomorrow, on another server, or after the numbers change. Saving these lines in a script turns them into a one-word health check.

Your project brief

Create the folder health and the file health/report.txt with exactly these four lines, each produced by commands (no typing the values yourself):
Host: codetemper (from hostname)
Errors: 3 (the number of lines containing ERROR in logs/app.log)
Listening on 8080: 1 (the number of lines in ss -tln output that contain :8080)
the JSON response of http://localhost:8080/health
Finally, make the report readable and writable only by you (600).

What the checks look for

  • Line 1 is Host: codetemper
  • Line 2 is Errors: 3
  • Line 3 is Listening on 8080: 1
  • Line 4 is the health JSON
  • The report is private (600)
  • Values come from real commands
Try it in the editor →

Take this with you

Small, reliable commands, combined carefully, become real operations tools.

Go a little further

Turn your commands into an executable script health.sh and run it with ./health.sh.

Learn Linux Command Line for free

20 short lessons with real code and instant checks.

See the whole course →