Skip to content

Automation

Python Scripts That Automate the AWS Tasks I Used to Do by Hand

TL;DR: I built a collection of Python scripts that automate common AWS operations -- backups, cost tracking, CloudFormation stack management, and resource cleanup -- so I stop repeating the same console clicks every week.

The Problem

AWS administration involves a surprising amount of repetitive manual work. Every week I was doing the same things: checking which EC2 instances were running, verifying backup status, looking up CloudFormation stack outputs, reviewing cost trends, and hunting for orphaned resources. Each task individually takes five minutes in the console, but collectively they eat an hour or more per week. Worse, manual processes are error-prone -- I once forgot to stop a dev instance that ran for an entire weekend.

What I Built

aws-scripts is a collection of standalone Python scripts using Boto3 that automate the AWS tasks I found myself doing repeatedly. Each script is self-contained, well-documented, and designed to run locally, in a Lambda function, or as a cron job.

  • Backup automation -- creates EBS snapshots and RDS snapshots on a schedule, tags them with retention policies, and cleans up expired snapshots automatically
  • Cost tracker -- pulls daily spend from AWS Cost Explorer, groups by service, and outputs a summary with week-over-week comparison. Optionally sends a Slack notification if spend exceeds a threshold
  • CloudFormation utilities -- list all stacks with their status, export stack outputs to a JSON file, detect stacks stuck in ROLLBACK_COMPLETE, and bulk-delete stacks matching a pattern
  • Resource inventory -- enumerates running EC2 instances, RDS databases, Lambda functions, and S3 buckets with key metadata (region, size, state, cost tags)
  • Cleanup scripts -- find and optionally terminate stopped EC2 instances older than N days, release unattached Elastic IPs, and delete unused security groups
  • Off-hours scheduler -- stops tagged dev/staging instances at 7 PM and starts them at 8 AM on weekdays

Tech Stack

Python, Boto3, AWS (EC2, RDS, S3, CloudFormation, Cost Explorer, Lambda, CloudWatch), Click CLI

Usage

# Install dependencies
pip install -r requirements.txt

# Run cost summary
python cost_tracker.py --days 7 --slack-webhook $SLACK_URL

# Backup all tagged volumes
python backup.py --tag Environment:production

# Clean up old snapshots
python cleanup_snapshots.py --older-than 30

Results

The off-hours scheduler alone saves roughly $200/month by stopping 6 dev instances during nights and weekends. The cost tracker caught a misconfigured NAT Gateway that was generating $45/day in unexpected data transfer charges. Automating snapshot cleanup freed 2.3 TB of stale EBS snapshots in the first run. What used to be an hour of weekly console clicking now runs unattended.


GitHub: https://github.com/basel5001/AWS_Scripts

An Interactive Bash Script for Linux User and Group Management

TL;DR: I built an interactive bash script that handles the most common Linux user and group administration tasks -- creating users, managing groups, setting permissions, and bulk operations -- through a menu-driven interface.

The Problem

Linux user management is straightforward if you have the commands memorized. But for junior admins, students, or anyone who does not manage Linux systems daily, remembering the exact syntax for useradd, usermod, groupadd, passwd, and their various flags is a constant trip to the man pages. One wrong flag and you have locked out a user or assigned the wrong shell. I wanted a tool that makes these operations safe and accessible while still being educational about what is happening under the hood.

What I Built

bash-scripting is an interactive menu-driven bash script for managing Linux users and groups. It wraps the standard Linux user management commands in a guided interface that validates input, confirms destructive actions, and logs everything it does.

  • User creation -- creates users with configurable home directories, shells, and group memberships. Validates that usernames follow naming conventions and prompts for password setup
  • User modification -- change shells, lock/unlock accounts, update group memberships, set password expiration policies, and modify home directories
  • User deletion -- removes users with optional home directory cleanup, confirms before executing, and logs the removal
  • Group management -- create, delete, and rename groups. Add or remove users from groups interactively
  • Bulk operations -- import a CSV of users and create them all in one run, or export the current user list to CSV for auditing
  • Password management -- force password resets, set expiration policies, and check password status across users
  • Audit logging -- every action is logged to /var/log/user-management.log with timestamps and the admin who ran it
  • Dry-run mode -- preview exactly what commands will execute before running them

Tech Stack

Bash, Linux (useradd, usermod, groupadd, passwd, chage), AWK, CSV parsing

Usage

# Run interactively
sudo ./user-manager.sh

# Bulk create users from CSV
sudo ./user-manager.sh --bulk-create users.csv

# Dry run
sudo ./user-manager.sh --dry-run

# CSV format: username,fullname,shell,groups
# john.doe,John Doe,/bin/bash,developers;sudo

Results

This script has been used as a teaching tool in a Linux administration course where students practice user management without risking misconfigured commands. The dry-run mode catches roughly one mistake per session that would have required manual cleanup. Bulk user creation from CSV reduced onboarding time for a 15-person lab setup from 45 minutes of manual work to under 2 minutes. The audit log has proven useful for tracking who made what changes during group lab exercises.


GitHub: https://github.com/basel5001/Bash-Scripting

How I Centralized CI/CD Governance Across 22+ Repos with a Single Repository

TL;DR: I built a single "infrastructure" repo that owns every reusable GitHub Actions workflow, composite action, and repository setting across my entire GitHub organization.

The Problem

Managing CI/CD pipelines across dozens of repositories is painful. Every repo had its own copy of linting configs, security scans, and Docker build steps. A single change -- like upgrading a scanner version -- meant opening 20+ PRs. Drift was inevitable, and nobody could answer "which repos actually run secret scanning?"

What I Built

githubinfra is a mono-repo that treats GitHub itself as infrastructure. Every workflow is a reusable workflow that any repo can reference with a one-liner. Repository settings (branch protection, merge strategies, topics, descriptions) are declared in a single repos.yml and synced via a TypeScript management tool.

  • 11 reusable workflows covering CI, linting, secret scanning, IOC/supply-chain checks, Docker builds, Terraform validation, SBOM generation, stale management, release notifications, branch copying, and label enforcement
  • 3 composite actions for environment setup (Python/Node/Go with caching), Docker Buildx builds, and Discord/Slack notifications
  • Declarative repo management -- edit repos.yml, run npm run sync, and every repo's settings converge to the desired state
  • Diff & dry-run modes so I can preview exactly what will change before applying
  • Automated workflow assignment -- new repos inherit the right pipelines from day one

Tech Stack

GitHub Actions, TypeScript, Terraform, GitHub REST API, YAML

Usage

Any repo references a shared workflow with two lines:

jobs:
  ci:
    uses: basel5001/githubinfra/.github/workflows/ci.yml@main
    with:
      language: python

To sync repository settings:

cd management && npm install
GITHUB_TOKEN=ghp_xxx npm run diff    # preview
GITHUB_TOKEN=ghp_xxx npm run sync    # apply

Results

What used to require touching 20+ repos now takes a single PR. Workflow updates roll out instantly to every consumer. The repos.yml file serves as a living inventory of the entire organization -- I can answer "what scanning does repo X run?" by reading one file. Onboarding a new repo takes under a minute: add it to repos.yml, push, done.


GitHub: https://github.com/basel5001/githubinfra

Autopilot Social Media: How n8n and AI Publish Content While I Sleep

TL;DR: I built an n8n automation that generates social media posts with GPT-4o, schedules them, and publishes across Facebook, Twitter, LinkedIn, and Instagram -- completely hands-free.

The Problem

Maintaining a consistent social media presence across four platforms is a full-time job. Each platform has different optimal posting times, character limits, and content styles. Hiring a social media manager is expensive. Using scheduling tools like Buffer or Hootsuite still requires you to write every post manually. I wanted something that generates the content, adapts it per platform, and publishes on schedule -- without me touching it after initial setup.

What I Built

n8n-social-automation is a self-hosted n8n workflow that uses GPT-4o to generate platform-specific social media content from a topic list, then publishes it on a schedule via each platform's API. The entire pipeline -- from content generation to publishing -- runs in Docker with zero manual intervention.

  • AI content generation -- GPT-4o writes posts tailored to each platform's style: professional for LinkedIn, punchy for Twitter, conversational for Facebook, visual-caption style for Instagram
  • Topic queue -- maintain a simple list of topics or RSS feeds; the workflow picks the next topic and generates fresh content
  • Multi-platform publishing -- posts to Facebook Pages, Twitter/X, LinkedIn company pages, and Instagram via their respective APIs
  • Scheduling -- configurable posting schedule per platform with timezone awareness
  • Image generation -- optionally generates accompanying images using DALL-E for visual platforms
  • Content review mode -- optional approval step that sends drafts to Slack before publishing
  • Analytics webhook -- receives engagement data back into n8n for tracking performance

Tech Stack

n8n, OpenAI GPT-4o, Docker, Facebook Graph API, Twitter API v2, LinkedIn API, Instagram API, Node.js

Usage

# Start n8n with Docker
git clone https://github.com/basel5001/n8n-social-automation.git
cd n8n-social-automation
cp .env.example .env  # add API keys
docker compose up -d

# Access n8n at http://localhost:5678
# Import the workflow JSON and activate it

Results

Over a 30-day test period, the automation published 120 posts across four platforms with zero manual intervention after setup. LinkedIn posts generated an average of 340 impressions each. The GPT-4o content required manual editing less than 5% of the time when content review mode was enabled. Total API costs for the month: approximately $8 for OpenAI, with all other platform APIs being free tier.


GitHub: https://github.com/basel5001/n8n-social-automation