DEV Community

Tanay Jain
Tanay Jain

Posted on

How I Built 5 Linux Automation Scripts on AWS EC2


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.

Here's what I built.


🖥️ Environment

Tool Details
Cloud AWS EC2 t2.micro
OS Ubuntu 22.04 LTS
Editor VS Code Codespaces
Auth SSH key-based authentication
Automation Bash scripting + cron jobs

📚 Topics Covered

Linux Fundamentals

  • User and group management
  • File permissions (chmod, chown)
  • Process management (ps, top, kill, systemctl)
  • Networking basics (ss, curl, UFW, DNS)
  • Package management with apt

Automation & Scripting

  • Bash scripting — functions and validation
  • Log management
  • Cron job scheduling
  • SSH workflows (scp, rsync)
  • Log analysis using grep, awk, and sed

🔧 The 5 Automation Scripts

By the end of the month, I had built and automated 5 production-style Bash scripts.


1. Server Health Check

A monitoring script that checks:

  • CPU usage
  • RAM usage
  • Disk usage
  • Service status
  • Internet connectivity

Scheduled every 15 minutes using cron.

./server_health.sh
Enter fullscreen mode Exit fullscreen mode

Example output:

================================================
        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

================================================
Enter fullscreen mode Exit fullscreen mode

2. Disk Usage Alerter

A script that scans partitions and generates alerts when disk usage exceeds a threshold.

Features:

  • Threshold-based alerts
  • Partition monitoring
  • Log generation
  • Color-coded terminal output

Runs every hour through cron.


3. Log Cleaner

A maintenance script that:

  • Compresses older logs
  • Removes outdated logs
  • Reduces disk usage automatically

Built using find, gzip, and mtime filters for log retention management.

Runs every Sunday.


4. User Creation Script

A provisioning script for creating users with a consistent setup.

Features:

  • Username validation
  • Group assignment
  • Home directory creation
  • Temporary password generation
  • Batch user creation using CSV files
sudo ./user_creation.sh --file users.csv
Enter fullscreen mode Exit fullscreen mode

5. Backup Script

Creates compressed backups using tar.gz archives.

Features:

  • Backup verification
  • Retention policy
  • Automatic cleanup of old backups
  • Logging and integrity checks

Scheduled daily at 2 AM.


⏱️ Cron Job Automation

All scripts were automated using cron jobs.

# 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
Enter fullscreen mode Exit fullscreen mode

Once configured, the server handled routine maintenance automatically.


💡 Biggest Learnings

1. Linux becomes comfortable through repetition

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.

2. Automation changes how you think

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.

3. Real infrastructure teaches different lessons

Working on an actual EC2 instance exposed me to problems that are difficult to fully understand in local environments:

  • SSH authentication issues
  • File permission problems
  • Cron debugging
  • Disk usage management
  • Log analysis workflows

Solving those problems on a live server taught me far more than just reading commands from documentation.


🚀 What's Next

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 Repository

All scripts and documentation are open source:

👉 github.com/tanayjdev/linux-bash-scripts


BCA Student • Aspiring Cloud & DevOps Engineer

Top comments (0)