mirror of
https://github.com/bigbeartechworld/big-bear-scripts.git
synced 2026-03-31 06:33:56 -04:00
This commit refactors all the shell scripts to use `#!/usr/bin/env bash` instead of `#!/bin/bash`. This change ensures that the scripts will run with the system's default Bash interpreter, even if it is not located at the standard `/bin/bash` path.
66 lines
1.5 KiB
Bash
66 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Default values
|
|
EMAIL=""
|
|
DISCORD_WEBHOOK=""
|
|
THRESHOLD=80
|
|
|
|
# Parse arguments
|
|
for ARG in "$@"
|
|
do
|
|
case $ARG in
|
|
--email=*)
|
|
EMAIL="${ARG#*=}"
|
|
;;
|
|
--discord=*)
|
|
DISCORD_WEBHOOK="${ARG#*=}"
|
|
;;
|
|
--threshold=*)
|
|
THRESHOLD="${ARG#*=}"
|
|
;;
|
|
*)
|
|
# Unknown option
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Prompt for email if not set
|
|
if [ -z "$EMAIL" ]; then
|
|
read -p "Please enter your email address (or press Enter to skip): " EMAIL
|
|
fi
|
|
|
|
# Prompt for Discord webhook if not set
|
|
if [ -z "$DISCORD_WEBHOOK" ]; then
|
|
read -p "Please enter your Discord webhook URL (or press Enter to skip): " DISCORD_WEBHOOK
|
|
fi
|
|
|
|
# Get disk usage
|
|
DISK_USAGE=$(df -h / | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 }')
|
|
USAGE=$(echo $DISK_USAGE | sed 's/%//g')
|
|
|
|
# Display current disk usage
|
|
echo "Current disk usage is $DISK_USAGE."
|
|
|
|
# Check if usage exceeds threshold
|
|
if [ $USAGE -ge $THRESHOLD ]; then
|
|
MESSAGE="Disk usage is at $DISK_USAGE - Time to clean up!"
|
|
|
|
# Send email if an email address is provided
|
|
if [ -n "$EMAIL" ]; then
|
|
echo "$MESSAGE" | mail -s "Disk Usage Alert" "$EMAIL"
|
|
fi
|
|
|
|
# Send message to Discord webhook if a webhook URL is provided
|
|
if [ -n "$DISCORD_WEBHOOK" ]; then
|
|
curl -H "Content-Type: application/json" \
|
|
-X POST \
|
|
-d "{\"content\": \"$MESSAGE\"}" \
|
|
"$DISCORD_WEBHOOK"
|
|
fi
|
|
else
|
|
MESSAGE="Disk usage is within acceptable limits."
|
|
fi
|
|
|
|
# Display the message
|
|
echo "$MESSAGE"
|