惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
博客园 - 三生石上(FineUI控件)
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
爱范儿
爱范儿
博客园 - 【当耐特】
雷峰网
雷峰网
S
SegmentFault 最新的问题
美团技术团队
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Built 5 Linux Automation Scripts on AWS EC2
Tanay Jain · 2026-05-23 · via DEV Community

Tanay Jain


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