Script for Disk usage

SebinnSebastian
May 26, 2022

--

We will discuss how to setup mail client and a script for disk usage alert

Step 1: Install mail client

sudo apt-get install mailutils  # For Ubuntusudo yum install mailx  # For RHEL,Centos

You will get prompts.Read the descriptions, Select the appropriate options.

Step 2: Create Disk Usage script.

cat > disk-usage.sh

#!/bin/sh
df -Ph | grep -vE ‘^Filesystem|tmpfs|cdrom’ | awk ‘{ print $5,$1 }’ | while read output;
do
echo $output
used=$(echo $output | awk ‘{print $1}’ | sed s/%//g)
partition=$(echo $output | awk ‘{print $2}’)
if [ $used -ge 80 ]; then
echo “The partition \”$partition\” on $(ip route get 1.2.3.4 | awk ‘{print $7}’) has used $used% at $(date)” | mail -s “Disk Space Alert: $used% Used On $(ip route get 1.2.3.4 | awk ‘{print $7}’)” <email-1>,<email2>
fi
done

bash disk-usage.sh

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

SebinnSebastian
SebinnSebastian

Written by SebinnSebastian

DevOps Engineer | Redhat Certified System Administrator | K8s Administrator | AWS, Docker, Terraform, GCP

No responses yet

Write a response