I set three log files to known ages with touch -d — exactly 30 days, 30 days and 12 hours, and 31 days — then ran what I thought was a 30-day retention policy:
find . -name '.log' -mtime +30
It returned one file: the 31-day-old one. The 30.5-day f...
A disk almost never fails loudly. It fills a percent at a time until writes stop, and at 100% nothing reports "disk full" — the database throws write errors about its own files, apps crash-loop, and logging a write itself stops recording at the exact...
A four-line YAML file port: 8080, supportemail, transport: tcp, reportdir: /var/reports and the rename most people type first: sed -i 's/port/listenport/g' app.yml. GNU sed 4.9 exited 0 and printed nothing, because -i never does. Afterwards the file ...
SC2086 sits at info, ShellCheck's lowest default severity, and fires on every unquoted $var, so it is usually the first rule anyone disables. I built the smallest test I could: a directory holding quarterly, report.txt and quarterly report.txt, and a...
A script that writes straight to the path a consumer reads can die halfway and leave a torn file that everything downstream loads as complete. No error appears anywhere, because the only process that failed is gone. I tested the fix the unfriendly wa...
A nine-line script, set -euo pipefail on line 2 and an ERR trap on line 3 whose only job is to print the failing command and its line number. A helper function then runs mkdir /proc/export, a directory that cannot be created. On bash 5.3.9 it printed...
Who owns that port? One ss flag answers it without sudo
For months my dev server started on 3001 because something already held 3000, and I kept stepping around it. When I finally asked, ss -ltn 'sport = :3000' showed the port listening on every in...
Level: Intermediate · Time: 7 min · Outcome: A mental model and three guards for unattended cron jobs
There's a gap between a script that works when you run it and a script that survives running unattended for a year. The first only has to succeed o...
Three Lines of Bash Stand Between Your Cron Job and a Silent Outage
Level: Intermediate · Time: 6 min · Outcome: A hardened, ShellCheck-clean cron wrapper generated for you
Three separate incidents taught me the same lesson over about a year. A /1...
Level: Intermediate · Time: 6 min · Outcome: A deploy that waits for its dependencies instead of racing them
I once spent forty minutes at eleven at night debugging a deploy that wasn't broken. The release script ran the database migration, the migr...
My Backup Hadn't Run in 9 Days and Nothing Told Me
Level: Intermediate · Time: 5 min · Outcome: A cron command that can't hang forever
The backup ran fine every night for fourteen months, and then it didn't run for nine days, and nothing told me. ...
A /1 rsync took our staging box to a load average of 41 one afternoon, and it took me longer than I want to admit to work out why. The sync normally finished in about twenty seconds. That day the backup target's NFS mount went sluggish, the sync star...
> Bash variables are global by default, so a helper function clobbered the caller's path variable and rm -rf cleaned up the wrong directory. local, return-as-status, and getopts — all in one incident.
Tags: #bash #linux #scripting #devops
The d...
We kept a plaintext file of hostnames, one per line, and a monitoring script read the file and pinged each host every five minutes. When a host failed to respond, the script sent an email alert. The system had been running for months and it worked — ...
The nightly backup looped over for f in $ls /data/exports and copied each file to a backup volume. It exited clean every night. For three weeks, green exit codes, no errors, nothing in the logs to suggest anything was wrong. The backup script had bee...
I meant to delete the .cache files under a data directory. The server had been running for two months and the cache layer had grown to about 14GB. The application team told me it was safe to purge it — they'd rebuilt the cache logic and the old files...
The backup ran every night at 2am and emailed me a green "847 files archived" summary. I'd built it, tested it against my own home directory where every file was named like report2024.csv, watched it sail through, and shipped it. For weeks the summar...
For three weeks a deployment pipeline reported every step green and shipped a build that had failed to compile on every single run. The build step ended in npm run build | tee build.log so the output could be archived. That pipe is the whole story: b...
A backup script of mine created a lock file on startup so two copies couldn't run at once — sensible. Then one night it hit an error partway through, set -e killed it on the spot, and it died without ever reaching the line that removes the lock. The ...
Every time I provision a new server — whether it's a $5 DigitalOcean droplet for a side project or a client's production box — there's a set of scripts I copy to /opt/scripts before I do anything else.
Not after the app is deployed. Not after the fi...