Tools: Ultimate Guide: How I Built 5 Linux Automation Scripts on AWS EC2

Tools: Ultimate Guide: How I Built 5 Linux Automation Scripts on AWS EC2

🖥️ Environment

📚 Topics Covered

Linux Fundamentals

Automation & Scripting

🔧 The 5 Automation Scripts

1. Server Health Check

2. Disk Usage Alerter

3. Log Cleaner

4. User Creation Script

5. Backup Script

⏱️ Cron Job Automation

💡 Biggest Learnings

1. Linux becomes comfortable through repetition

2. Automation changes how you think

3. Real infrastructure teaches different lessons

🚀 What's Next

📁 GitHub Repository I wanted to find out what working on a real Linux server actually feels like — not a local VM, not a simulator. So in May 2026, I spun up an Ubuntu 22.04 server on AWS EC2, connected via SSH, and spent the entire month doing real work on it. By the end of the month, I had built and automated 5 production-style Bash scripts. A monitoring script that checks: Scheduled every 15 minutes using cron. A script that scans partitions and generates alerts when disk usage exceeds a threshold. Runs every hour through cron. A maintenance script that: Built using find, gzip, and mtime filters for log retention management. A provisioning script for creating users with a consistent setup. Creates compressed backups using tar.gz archives. Scheduled daily at 2 AM. All scripts were automated using cron jobs. Once configured, the server handled routine maintenance automatically. At the beginning, basic terminal commands felt unfamiliar. After working daily on a remote server, navigating Linux from the command line became much more natural. There's no shortcut — you just have to do it daily. One of the biggest mindset shifts was noticing repetitive work and immediately thinking: "Can this be automated?" That shift alone made scripting feel much more practical — and honestly, more fun. Working on an actual EC2 instance exposed me to problems that are difficult to fully understand in local environments: Solving those problems on a live server taught me far more than just reading commands from documentation. Next, I'm moving into AWS Core Infrastructure — VPC, IAM, RDS, and Terraform. That work starts in June 2026. Follow along if you're on a similar path. 👉 github.com/tanayjdev/linux-bash-scripts BCA Student • Aspiring Cloud & DevOps Engineer Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Code Block

Copy

./server_health.sh ./server_health.sh ./server_health.sh ================================================ SERVER HEALTH CHECK REPORT ================================================ Date: 2026-05-12 10:00:00 Hostname: ip-172-xx-xx-xx --- CPU Usage --- ✅ CPU is OK (2.3%) --- Memory Usage --- ✅ RAM is OK (45%) --- Services Status --- ✅ ssh: RUNNING ✅ nginx: RUNNING ✅ docker: RUNNING --- Network --- ✅ Internet: CONNECTED ================================================ ================================================ SERVER HEALTH CHECK REPORT ================================================ Date: 2026-05-12 10:00:00 Hostname: ip-172-xx-xx-xx --- CPU Usage --- ✅ CPU is OK (2.3%) --- Memory Usage --- ✅ RAM is OK (45%) --- Services Status --- ✅ ssh: RUNNING ✅ nginx: RUNNING ✅ docker: RUNNING --- Network --- ✅ Internet: CONNECTED ================================================ ================================================ SERVER HEALTH CHECK REPORT ================================================ Date: 2026-05-12 10:00:00 Hostname: ip-172-xx-xx-xx --- CPU Usage --- ✅ CPU is OK (2.3%) --- Memory Usage --- ✅ RAM is OK (45%) --- Services Status --- ✅ ssh: RUNNING ✅ nginx: RUNNING ✅ docker: RUNNING --- Network --- ✅ Internet: CONNECTED ================================================ sudo ./user_creation.sh --file users.csv sudo ./user_creation.sh --file users.csv sudo ./user_creation.sh --file users.csv # Health check — every 15 minutes */15 * * * * /home/ubuntu/scripts/server_health.sh >> /home/ubuntu/logs/health_cron.log 2>&1 # Disk alerter — every hour 0 * * * * /home/ubuntu/scripts/disk_alerter.sh >> /home/ubuntu/logs/disk_cron.log 2>&1 # Backup — daily at 2 AM 0 2 * * * /home/ubuntu/scripts/backup.sh >> /home/ubuntu/logs/backup_cron.log 2>&1 # Log cleaner — every Sunday at 11 PM 0 23 * * 0 /home/ubuntu/scripts/log_cleaner.sh >> /home/ubuntu/logs/cleaner_cron.log 2>&1 # Health check — every 15 minutes */15 * * * * /home/ubuntu/scripts/server_health.sh >> /home/ubuntu/logs/health_cron.log 2>&1 # Disk alerter — every hour 0 * * * * /home/ubuntu/scripts/disk_alerter.sh >> /home/ubuntu/logs/disk_cron.log 2>&1 # Backup — daily at 2 AM 0 2 * * * /home/ubuntu/scripts/backup.sh >> /home/ubuntu/logs/backup_cron.log 2>&1 # Log cleaner — every Sunday at 11 PM 0 23 * * 0 /home/ubuntu/scripts/log_cleaner.sh >> /home/ubuntu/logs/cleaner_cron.log 2>&1 # Health check — every 15 minutes */15 * * * * /home/ubuntu/scripts/server_health.sh >> /home/ubuntu/logs/health_cron.log 2>&1 # Disk alerter — every hour 0 * * * * /home/ubuntu/scripts/disk_alerter.sh >> /home/ubuntu/logs/disk_cron.log 2>&1 # Backup — daily at 2 AM 0 2 * * * /home/ubuntu/scripts/backup.sh >> /home/ubuntu/logs/backup_cron.log 2>&1 # Log cleaner — every Sunday at 11 PM 0 23 * * 0 /home/ubuntu/scripts/log_cleaner.sh >> /home/ubuntu/logs/cleaner_cron.log 2>&1 - User and group management - File permissions (chmod, chown) - Process management (ps, top, kill, systemctl) - Networking basics (ss, curl, UFW, DNS) - Package management with apt - Bash scripting — functions and validation - Log management - Cron job scheduling - SSH workflows (scp, rsync) - Log analysis using grep, awk, and sed - Service status - Internet connectivity - Threshold-based alerts - Partition monitoring - Log generation - Color-coded terminal output - Compresses older logs - Removes outdated logs - Reduces disk usage automatically - Username validation - Group assignment - Home directory creation - Temporary password generation - Batch user creation using CSV files - Backup verification - Retention policy - Automatic cleanup of old backups - Logging and integrity checks - SSH authentication issues - File permission problems - Cron debugging - Disk usage management - Log analysis workflows - Joined Apr 5, 2025