Shell Script to Watch Disk Space1 min read

The first step in your fancy Bash script is to get disk space like this.

Output

Next, let’s focus on grabbing the percentage of space used on each device..

Output

Shell Script

Let’s take this info and write a simple shell script. The previous command displays fields 5 and 1 of the df command. Now all you need to do is write a script to see if the percentage of space is >= 90%.

and paste.

Replace your_user@gmail.com with your proper email account. Next, we’ll need to set it up as executable and add it to our cronjobs.

Install as cronjob:

Finally, add this to your cronjob list.

This will make it run at 12:10 A.M. every day. It will automatically email an alert if you’re over 90% used on any one of your volumes.

Zack

Zack

I love learning new things and trying out the latest technology.

You may also like...

Leave a Reply