Linux disk space alerts on Discord


Linux disk space alerts on Discord

Linux disk space alerts. Check your space and be responsible with your project. Take care of your space and don’t crack the project.

This is a very simple and handy tutorial about how to check the disk space every day and send the alert using Discord.

Prerequisite:

  • discord webhook

Create the script

Create new file check-disk.sh:

#!/bin/bash

# This variable holds the usage disk space in percents
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')

# The threshold where the alert will be sent. By default is 90, so when your server disk usage cross this border, the alerts will come on your discord.
THRESHOLD=90

# The url of the webhook. You can copy this value from Discord.
DISCORD_WEBHOOK_URL=<Your webhook url here without tags>

# The name of the project. You can put whatever you want here.
PROJECT_NAME="<project name without tags>"
# The url of the project.
PROJECT_URL=<project url without tags>

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then

curl --location --request POST "$DISCORD_WEBHOOK_URL" \
--form "content=\":floppy_disk: The disk space for $PROJECT_NAME - $PROJECT_URL is critical.
Used: $CURRENT%. 
Please clean up some space.\" " \
--form 'username="Disk Space Alert"'

fi

Make the script executable

Be sure that you have permissions to at least 755 set.

sudo chmod +x /home/ubuntu/check-disk.sh

!!! Use your full path the the file

Automate the script

crontab -e

and at the end of the file enter

0 6 * * * /bin/bash /home/ubuntu/check_disk.sh

!!! Use your full path the the file

Newsletter


Related Posts

Get your Jenkins Passwords from secrets

How to get your Jenkins passwords from your secrets credentials. Follow this simple tutoriale and find your password or ssh private key.

How to launch a 6 figures startup with 0$ investment

Are you curious how to launch a startup in the fast and effective way? Here's not the answer, but you can understand how to achieve it

How to cold email

How to cold email - a practical guide about how to use cold email in your activity as a CEO of a software agency or startup owner.

Git clone private repo in docker

A simple how to guide to use git clone of a private repository inside docker container. With vuejs / nodejs app.

How to detect the browser language in javascript

How to detect the browser language in javascript in just a line of code. The method is working on all major browser

You don't need a macbook pro to be a pro

You don't need a macbook pro to be a pro! You need a laptop and internet connection, and a brain, but you already have it

Free templates for startup

Free HTML templates for startup or a new project. A complete list with free resources to build your next startup's website and gain the traction to the sky.

What I learned to never do in a presentation meeting

What I learned to never do in a presentation meeting. I had a very bad meeting experience with a gateway provider.

Startup graveyard is a series of killed projects that made millions in revenue per year

Startup graveyard is a series of killed projects that made millions in revenue per year. Just watch their graveyard and do it your own. What better validation do you expect.

How do you detect Credit card type based on the number?

How do you detect Credit card type based on the number using JavaScript? Simple solution using only code, no library required.