100%
GRIMOIRE
GrimoireDindon CorpusSynthesis VolumesThe Foundation of Iron
FRENAR
← PreviousNext →
RATIO
THE FOUNDATION OF IRON · COURSE MATERIAL · WEEK 10
◆◆◆
LINUX ADMINISTRATION
LEVEL 2
Week 10 of 26 · Block 5 — Bare Metal OS
8h theory · 27h practice
◆ WEEKLY LEARNING OBJECTIVES

1. Schedule automatic tasks with cron
2. Write simple shell scripts to automate repetitive tasks
3. Manage and rotate system logs
4. Set up basic monitoring of a server
5. Configure simple alerts on defined thresholds

◆◆◆
⚠ WARNING — SHELF LIFE OF VERSIONS REFERENCED HERE

Monitoring and alerting tools evolve rapidly in the Linux ecosystem. This material presents generic principles applicable to any such tool; the instructor must choose and adapt the concrete tool (basic command-line scripting or a more comprehensive solution) based on what is relevant and actively maintained at the time of teaching.

Amine RAITI · Infrastructure Architect & SRE
Public document · CC BY-NC-SA 4.0 · AI Powered by Amine
Opération Dindon
RATIO
COURSE OUTLINE · 8H
THEORY GUIDING THREAD
10.1 · Task scheduling with cron2h
— Syntax of a cron entry (minute, hour, day of month, month, day of week)
— Concept of a user crontab vs a system crontab
— Typical use cases: scheduled backups, automatic cleanup, periodic reports
10.2 · Shell scripts3h
— Structure of a shell script: shebang, variables, conditions, loops
— Direct link with the conditional logic from Weeks 3/4 — same principle, different syntax
— Best practices: basic error handling, comments, execution permissions
10.3 · Log rotation and management2h
— Why rotate logs: avoiding disk space saturation (link with Week 7)
— Rotation principle: archiving, compression, deletion after a defined period
10.4 · Basic monitoring and alerts1h
— Generic monitoring principles: what to watch (CPU, RAM, disk, critical services), reasonable alert thresholds
— Link with the idea of planned capacity rather than reactive firefighting
EXAMPLE TO DEVELOP ON THE BOARD

A cron entry "0 2 * * *" triggers a task every day at 2am — break down each field in front of the trainees and vary one field to illustrate different frequencies (every hour, once a week).

RATIO
EXERCISE 1 · AUTOMATING ROUTINE TASKS · 14H

Equipment: the system configured in Week 9, terminal access.

(3h) Writing a first simple shell script: automatic backup of a given folder into a timestamped compressed archive.
(3h) Improving the script with basic error handling (checking the source folder exists before starting the backup, clear message on failure).
(3h) Scheduling the backup script via cron for a daily run at a defined time, verifying it triggers correctly (forcing an immediate run for testing, then checking in the logs that the scheduled run actually took place).
(3h) Writing a second script: automatically cleaning up backups older than 7 days, to avoid disk space saturation (direct link with Week 7).
(2h) Full testing of the backup + cleanup chain across several simulated runs, verifying the expected behaviour.
SOLUTION — EXERCISE 1

Expected structure of the backup script: a shebang on the first line, a variable defining the source folder and the destination folder, a conditional check for the source folder's existence, a compression command with a timestamp in the generated file's name, a confirmation or error message in the output.

Point of attention for cron scheduling: check that the script has the necessary execution permissions and that the paths used in the script are absolute (cron does not run within the same directory context as an interactive session).

RATIO
EXERCISE 2 · SETTING UP SIMPLE ALERTS · 13H

Equipment: the system configured in Exercise 1, terminal access.

(3h) Writing a disk space monitoring script: periodically checking usage percentage and triggering an alert (a message in a dedicated log) if a given threshold (e.g. 80%) is exceeded.
(3h) Extending the script to also monitor CPU load and memory usage, with separate thresholds for each resource.
(3h) Scheduling the monitoring script via cron at a regular interval (e.g. every 15 minutes).
(2h) Testing the alert trigger by artificially simulating a load or disk fill near the defined threshold.
(2h) Writing a summary sheet documenting the full automation and monitoring setup put in place over the week.
SOLUTION — EXERCISE 2

Expected structure of the monitoring script: retrieving the current value (disk percentage, CPU load, memory usage) via the appropriate system commands, comparing it against a threshold defined as a variable, writing a timestamped alert line to a dedicated log file if the threshold is exceeded.

Central teaching point: stress that this basic script-based monitoring approach is a pedagogical starting point — in a real production environment, dedicated monitoring tools (to be chosen based on what is maintained and relevant at the time of teaching) offer far more comprehensive features (history, dashboards, multi-channel alerts).

◆ SUMMARY SHEET — WEEK 10 SELF-ASSESSMENT
1. I can write the syntax of a cron entry.
2. I can write a simple shell script with basic error handling.
3. I can schedule a script's automatic execution with cron.
4. I can explain why log rotation is necessary.
5. I can monitor disk space, CPU load and memory usage from the command line.
6. I can define a reasonable alert threshold for a system resource.
7. I can trigger a basic automatic alert when a threshold is exceeded.
8. I can document an automation setup that has been put in place.
← PreviousNext →