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

Leader 1 5 42
calendar_todayschedule1 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.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

My Nginx Died at 2 AM and Nobody Noticed for 6 Hours. Now I Have a Watchdog Script

BashSnippets - May 21

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

Dharanidharan - Feb 9

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

I Spent 40 Minutes at 11pm Debugging a Deploy That Wasn't Broken

BashSnippets - Jul 1
chevron_left
2.9k Points48 Badges
North Americabashsnippets.xyz
34Posts
26Comments
3Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
3 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!