The Cleanup Script Exited 0 and Reported Success — Then Scaling Blew Up Three Days Later: 7 Shell Safety Audits to Run Before Any Script Goes to Production

Overview Start with the conclusion: an exit code of 0 does not mean the script behaved. That sounds obvious, yet every year it burns someone in a production environment in a slightly different way. Last year, on an e-commerce order fulfillment system, I hit this: a cleanup script that ran every night at 1 a.m. and pruned old release directories under /data/apps/order-api/releases/. It had run for two years with nothing but a clean clean done in the log....

November 30, 2026 · 24 mins · 4909 words · ABao

Practical Shell Script Automation Tips

Introduction Shell scripts are the most common automation tool for operations engineers. This post records several practical patterns used in the field. Log Rotation Cleanup #!/bin/bash # clean_logs.sh - Log cleanup script LOG_DIR="/var/log/app" KEEP_DAYS=30 find "$LOG_DIR" -name "*.log" -type f -mtime +${KEEP_DAYS} -exec gzip {} \; find "$LOG_DIR" -name "*.gz" -type f -mtime +${KEEP_DAYS} -delete echo "$(date): Log cleanup complete, kept ${KEEP_DAYS} days" Run daily via crontab: 0 2 * * * /opt/scripts/clean_logs....

January 11, 2024 · 2 mins · 369 words · ABao

Production-Grade Bash Scripting Guide

Overview Bash is the most widely used scripting language in the ops world — nearly every Linux server ships with the interpreter, requiring no runtime installation. But Bash is also the language most prone to producing scripts that “work but can’t be trusted”: no type checking, errors are silent by default, variables get word-split without quotes, and pipeline failures get swallowed. The root cause of many production incidents is a Bash script that didn’t handle errors properly....

December 27, 2023 · 22 mins · 4513 words · ABao