Skip to content

CarlosSemeao/linux-automation-toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛠️ Linux Automation Toolkit

Bash scripting • Cron jobs • Git workflow • Docker containerization
Part of my CompTIA Linux+ XK0-005 hands-on study path.


✅ Feature-to-Skill Map

Feature What it Proves
Bash script for disk alerts Able to write and execute shell scripts to monitor system usage
Cron job automation Knows how to schedule repetitive tasks using crontab
Docker container execution Understands script containerization and basic Dockerfile syntax
Git version control Proficient in Git commit flow and history cleanup (rebase, squash)
Markdown documentation Can write clear, structured technical documentation in README.md
Screenshot validation Proves command-line output through real-world terminal screenshots

📂 Folder Structure

linux-automation-toolkit/
├── scripts/
│   └── disk_alert.sh          # disk usage monitoring script
├── cron/
│   └── daily-job.txt          # crontab entry (runs 08:00 daily)
├── docker/
│   ├── Dockerfile             # container build instructions
│   └── disk_alert.sh          # script copy used in the image
├── docs/
│   ├── bash-basics.md         # quick Bash recap
│   └── version-control-notes.md
├── screenshots/               # proof-of-work images
│   ├── 01-disk-alert-script-nano.png
│   ├── 02-disk-alert-script-execution.png
│   ├── 03-disk-alert-log-output.png
│   ├── 04-cron-disk-alert-entry.png
│   └── 05-docker-run-disk-alert.png
└── README.md

📜 disk_alert.sh (Bash Script)

Monitors / disk usage and appends a status line to /var/log/disk_alert.log.

#!/bin/bash
LOGFILE="/var/log/disk_alert.log"
THRESHOLD=80

USAGE=$(df / | tail -1 | awk '{print $5}' | tr -d '%')

if [ "$USAGE" -ge "$THRESHOLD" ]; then
    MESSAGE="$(date): WARNING – Disk usage is at ${USAGE}%"
else
    MESSAGE="$(date): OK – Disk usage is at ${USAGE}%"
fi

echo "$MESSAGE" >> "$LOGFILE"

Key Bash concepts: shebang, variables, command substitution, awk, comparison operators, redirection.


📅 Cron Job Automation

Step Command Purpose
1️⃣ sudo crontab -e Edit root crontab
2️⃣ Add line → 0 8 * * * /Users/carlossemeao/linux-automation-toolkit/scripts/disk_alert.sh Run script daily @ 08:00
3️⃣ sudo crontab -l Confirm job installed

📸 Screenshot:
Cron Entry

Log sample:

Wed 11 Jun 2025 08:00:01 BST: OK – Disk usage is at 9%

🐳 Docker Container Execution

A minimal image runs the script in isolation.

docker/Dockerfile

FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y bash coreutils && rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/log
COPY disk_alert.sh /usr/local/bin/disk_alert.sh
RUN chmod +x /usr/local/bin/disk_alert.sh
CMD ["/usr/local/bin/disk_alert.sh"]

🔧 Build & Run

cd linux-automation-toolkit
docker build -t disk_alert.img ./docker
docker run --rm disk_alert.img

📸 Screenshot:
Docker Run


📸 Development Screenshots

# Description Image
1 Script written in nano 01
2 Manual execution test 02
3 Log output on host 03
4 Cron job entry 04
5 Docker container output 05

🧠 Lessons Learned

  • Bash: variables, loops, conditions, logging
  • Cron: scheduling, redirection to log files
  • Docker: Dockerfile basics, custom entrypoint, container testing
  • Git: clean repo structure, meaningful commits, Markdown documentation

🚀 How to Extend

  • Parameterize the script to monitor multiple mount points.
  • Add email or Slack notifications on warning.
  • Use Docker volumes to persist logs outside container.
  • Integrate this with Ansible for fleet-wide deployment.

📜 License

MIT

About

Bash automation | Cron jobs | Git | Optional Docker | CompTIA Linux+ Section 128–145

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published