I built a couple bash scripts this week after my server crashed Thursday at 11pm

I built a couple bash scripts this week after my server crashed Thursday at 11pm

●2 ●38 ●102
calendar_today • schedule1 min read
— Originally published at bashsnippets.xyz

My disk hit 100% on a Thursday night. Just a silent crash and a bunch of errors I found the next day.
I had nothing running in the background watching for problems.

**

  1. Disk space warning**
    The script I needed before that Thursday happened.
`#!/bin/bash
THRESHOLD=80
USAGE=$(df / | awk 'NR==2{print $5}' | tr -d '%')

if [ "$USAGE" -gt "$THRESHOLD" ]; then
  echo "⚠ Disk at ${USAGE}% — time to act"
else
  echo "✓ Disk OK: ${USAGE}% used"
fi`

I just happened to be doing some brushing up on crontab a bit lately so I automated the script before I did anything else, so this wouldn't happen again.
Full script with email alerts → bashsnippets.xyz/snippets/disk-space-warning.html

2. Killing Processes
I also found myself continuing to fall into a ps aux | grep ""
loop after cleaning up the disk and new there was a one-word command out there that made it easier, but I couldn't recall...
I had to google it a few times before it stuck with me:

pkill/pgrep <--- turned a 4 command work-flow into a one-word workflow:
My loop was this:

ps aux | grep myapp   # find it
kill 12345            # copy/paste PID
ps aux | grep myapp   # confirm it died

After, it was this:

pgrep -l myapp
pkill -x myapp

Where this went:

So, of course, these and a few more, like error handling, turned into a free, and growing script library at bashsnippets.xyz — copy-paste ready, explained line by line, no signup.

I also started turning each one into a short video on YouTube (@BashSnippets). Hoping to gain some traction in the beginner bash communities!

Hope someone can find some use of this, but What are you automating? Drop it in the comments.


I bundled the scripts I copy onto every new server, plus 10 bonus ones, into the Production Bash Toolkit. 30-day refund if it isn't useful.

Want more #linux & #bash deep dives?

Join 6,093+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9

Cloudflare Blocked My Server, So I Made My Visitors' Browsers Do the Fetching

bryanhamiltondevverified - Nov 15

A deploy guard that passes with no token

BashSnippets - Nov 24

I built a free bash script library because I kept Googling the same 10 scripts over and over

BashSnippets - May 6

My Script Crashed and Left a Lock File Behind. Every Run After That Refused to Start.

BashSnippets - Jun 11
chevron_left
3.8k Points • 142 Badges
North America • bashsnippets.xyz
79Posts
38Comments
14Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Related Jobs

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!