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

Managerflota idea validation

Managerflota idea validation thread. Manage the car hailing business in one web app.

Generate hexagons in JS based on center coordinates and radius

How to generate hexagons in javascript based on the center point coordinates and radius length

How to generate referral codes in javascript

How to generate referral codes in javascript very fast with less code

Loop over directories in bash and execute commands

How to loop over directories in bash and execute multiple commands

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

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 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