README.md

Download
markdown 57 lines 2.7 KB
 1# Linux Examples
 2
 3Example scripts illustrating operational and diagnostic concepts covered in the Linux study topic.
 4
 5## Scripts
 6
 7### `disaster_recovery.sh`
 8
 9Simulates a disaster recovery planning checklist. Teaches key DR concepts through hands-on verification:
10
11- **Backup verification** — checks backup age against RPO threshold and validates file size
12- **Service health checks** — confirms critical services are running using `systemctl` or `pgrep`
13- **Database backup simulation** — mimics `pg_dump` output validation
14- **Network connectivity** — ensures recovery-path hosts are reachable
15- **Disk space monitoring** — flags filesystems that would block a restore
16- **Recovery simulation** — walks through a step-by-step tabletop exercise (failover scenario)
17
18```bash
19chmod +x disaster_recovery.sh
20./disaster_recovery.sh --check      # run all health checks
21./disaster_recovery.sh --simulate   # walk through recovery steps
22./disaster_recovery.sh --report     # full readiness report with pass/warn/fail counts
23```
24
25### `performance_diagnostics.sh`
26
27Diagnoses CPU, memory, disk I/O, and network bottlenecks. Explains what each metric means and how to act on it:
28
29- **CPU analysis** — load average, load/core ratio, top CPU consumers, zombie processes
30- **Memory analysis** — RAM utilization, page cache, swap usage, top memory consumers
31- **Disk I/O** — filesystem usage, `iostat` throughput and `%util`, `/proc/diskstats` fallback
32- **Network analysis** — TCP connection states, listening ports, interface byte counters
33- **Summary report** — consolidates all findings with severity (CRIT / WARN / OK) and remediation hints
34
35```bash
36chmod +x performance_diagnostics.sh
37./performance_diagnostics.sh --all      # full analysis + bottleneck summary
38./performance_diagnostics.sh --cpu      # CPU only
39./performance_diagnostics.sh --memory   # memory only
40./performance_diagnostics.sh --disk     # disk I/O only
41./performance_diagnostics.sh --network  # network only
42```
43
44## Prerequisites
45
46| Tool | Purpose | Install |
47|------|---------|---------|
48| `bash` 4+ | Script runtime | built-in (macOS ships bash 3; use `brew install bash`) |
49| `ps`, `df`, `ping` | Core metrics | built-in on Linux and macOS |
50| `iostat` | Disk I/O statistics | `sudo apt install sysstat` / `brew install sysstat` |
51| `ss` | Socket statistics | `sudo apt install iproute2` (Linux); use `netstat` on macOS |
52| `netstat` | Network connections | built-in on macOS; `sudo apt install net-tools` on Linux |
53| `systemctl` | Service status | systemd-based Linux distros only |
54| `free` | Memory summary | Linux only; macOS uses `vm_stat` (handled automatically) |
55
56Both scripts detect the OS at runtime and fall back gracefully when a tool is unavailable.