Configure Windows Script to Check Disk Space and Send Email Alerts

Summary

When you find your computer run slower and slower, it is not only the problem of the computer, you can also check the hard disk space. Now I will show you how to avoid the low speed of the computer operation due to low disk space and show you how to configure Windows script to check disk space and send email alerts to you when the hard disk has little space.

Andrew Wright

10/08/2019

by Andrew Wright

Follow @IM-Magic

How to Use Windows Script to Check Disk Space and Send Email Alerts

Setting up Windows script to check disk space can effectively monitor the state of the hard disk space and prevent low disk space problems.

Now you can configure the hard disk monitor to check the hard disk space and send email alerts to you when the hard disk is about to run out of space.

You can create a script as follows to check the hard disk and save it to your home directory:

#!/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 you can add this command line at at the end of /etc/crontab file:

@daily ~/sample.sh

And you need to change the email in to your email address. The threshold of the used hard disk space is set as 90% here, which means when the used hard disk space is up to 90%, the system will send a low disk space to your email.

What to Do when Hard Disk Send You Low Disk Space Alert

When you hard disk send low disk space alert to you, it means your system drive space has been used more than 90%. Then you will need to manage the hard disk space as soon as possible. Here are some solutions for you.

Clean up Junk Files on the System Drive

First delete those useless files on the system drive to spare some space on the system drive. You can delete the temp files and uninstall some useless programs.

Enlarge C Drive with System Built-in Tools

You can use system tools to extend the C drive first, you can try “My Computer”>”Manage”>”Disk

Management”, right click the C drive, choose “Extend Volume”.

You can also use diskpart command prompt to extend C drive.

1. Press “Win+R”, type “CMD”.

2. Type “diskpart” in the command window.

3. Type “list volume” .

4. Type “select volume X (X is the drive letter of your C drive.) to go

5. Type “extend size=10240 (size stands for the capacity you will extend by and the unit is MB) and Enter

But these two solutions are only for the situation when there are unallocated space adjacent to the C drive.

Resize the Disk Partition with Partition Manage Freeware

There are many limitations of Windows system tools to extend partitions, they can only work when there is unallocated space adjacent to the C drive. And using diskpart command prompt sometimes can cause you data loss problems. Here I would like to recommend a better solution to you.

IM-Magic Partition Resizer Free is a partition manage program which is totally free for Windows 10/7/8/XP/Vista. It has remarkable partition manage speed which is much faster than other partition software. And it is a 100% safe program, you can try it.

download free windows 10 partition software

Free to resize disk partition with partition manage toolFree to resize disk partition with partition manage tool

If you use Windows Server system, you can also download their Server edition, IM-Magic Partition Resizer Server, which is compatible for all the server system, and free for trail.

download free windows 10 partition software

Related Product