Create Script to Check Disk Space and Send Email Alerts for Low Disk Space

Summary

If you want your hard disk in better monitoring, you can create script to monitor the hard disk, it will send you alert email if your hard disk is in low space, which can prevent system crash due to the C drive is full.

Andrew Wright

10/05/2022

by Andrew Wright

Follow @IM-Magic

How to Create Script to Check Disk Space and Send Email Alerts for Low Space

Low disk space on the C drive sometimes may cause you big trouble, you will find your computer run much slower, and you can not install programs on your computer, there might even be a system crash on your computer due to the low space C drive. If you want to avoid these problems, you need to create a script to check disk space and set up a threshold of disk space, then configure email alerts for low disk space.

You can create this script bellow to alert you when the disk is almost full, the threshold is 90% here, and you only need to change the email address in the script into yours.

#!/bin/bash

CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')

THRESHOLD=90

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

mail -s 'Disk Space Alert' mailid@domainname.com << EOF

Your root partition remaining free space is critically low. Used: $CURRENT%

EOF

fi

Then save this script to the file sample.sh in the home directory. And then put the line following at the end of /etc/crontab file.

@daily ~/sample.sh

Then you can receive email alert when the space of hard disk is low.

How to Free up C Drive when You Receive the Low Disk Space

To solve the fundamental problem, you need to know how to free up space of C drive when your disk is full. When your system drive is in low disk space situation, you will find your computer run slower and slower, it often stuck in one process. And you can not download any files and install programs.So, how to enlarge the system drive when the system drive is full?

So, how to enlarge the system drive when the system drive is full?

First, you can try extend volume function of Disk Management tool or diskpart command prompt to extend C drive if you have unallocated space adjacent to it.

If you don’t have unallocated space adjacent to system drive, you can also try a easier solution:

partition manege tool, here we recommend a reliable freeware to you, IM-Magic Partition Resizer free, which is 100% safe and effective, what’s important is that this free edition is totally free for Windows 10/7/8/XP/Vista.

Enlarge C drive on Windows with partition toolEnlarge C drive on Windows with partition tool

download free windows 10 partition software

If you use Windows sever system, you can also free download server edition here:

download free windows 10 partition software

Related Product