Scripting & Automation

The Glue of Infrastructure

While tools like Terraform build the house, scripting handles the daily chores. I use a mix of languages to create custom tooling, automate API hooks, and handle system maintenance without human intervention.

💻 Bash:
Server-side automation, log rotation, and cron jobs.

🐍 Python:
Complex logic, data parsing, and Cloud SDK integrations.

⚙️ PowerShell:
Cross-platform management and Azure automation.

Tool 1: Bash (The System Glue)

Bash is my go-to for rapid interactions with the Linux kernel. It is perfect for piping commands together to solve immediate problems on a server.

Real World Use Case: System Health Monitor

A script that checks disk usage and sends an alert if it exceeds 90%.

monitor.sh
#!/bin/bash

# Get the current disk usage percentage of root /
USAGE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
THRESHOLD=90

if [ "$USAGE" -gt "$THRESHOLD" ]; then
    echo "⚠️ WARNING: Disk space is critical at $USAGE%!"
    # In production, we pipe this to mail or Slack
    # echo "Disk Full" | mail -s "Alert" admin@example.com
else
    echo "✅ System Healthy: Disk usage at $USAGE%."
fi

Tool 2: Python (Logic & APIs)

When logic gets too complex for Bash (e.g., parsing JSON or interacting with REST APIs), I switch to Python. It is the industry standard for glue code in cloud environments.

Real World Use Case: Automated Webhook Trigger

A script that queries an API and triggers a deployment if a specific condition is met.

deploy_hook.py
import requests
import os

API_URL = "https://api.github.com/repos/my-user/my-repo/releases/latest"
DEPLOY_WEBHOOK = os.getenv("DEPLOY_WEBHOOK_URL")

def check_for_updates():
    response = requests.get(API_URL)
    data = response.json()
    
    latest_version = data['tag_name']
    print(f"Latest version found: {latest_version}")

    # Logic: If version is v2.0, trigger the pipeline
    if latest_version == "v2.0.0":
        print("🚀 Triggering Deployment Pipeline...")
        requests.post(DEPLOY_WEBHOOK, json={"event": "update_found"})

if __name__ == "__main__":
    check_for_updates()

Tool 3: PowerShell (Object Oriented)

PowerShell isn't just for Windows anymore. I use PowerShell Core (pwsh) for its powerful object-oriented pipeline, which is often cleaner than text parsing in Bash.

audit_users.ps1
# Get all users, filter by 'LastLogon', and export to CSV
Get-LocalUser | 
  Select-Object Name, Enabled, LastLogon | 
  Where-Object { $_.Enabled -eq $true } | 
  Export-Csv -Path "./user_audit.csv" -NoTypeInformation

Write-Host "✅ User audit complete. Data saved to user_audit.csv" -ForegroundColor Green

⚡ When to use what?

LanguageBest Use CaseAvoid When...
BashSimple server tasks, file manipulation, piping commands.You need complex data structures (JSON/Arrays).
PythonAPI interactions, heavy logic, cross-platform scripts.You just need to run a quick one-liner command.
PowerShellManaging Azure resources, Active Directory, Object manipulation.Running simple scripts on a minimal Linux Alpine container.