Watching/Maintaining harddrives can be a pain (or your best friend) depends on the situation. Maintaining alot of server's with multiple harddrives; one needs to know how to manage and watch their harddrives, so one know if its getting full or when you need to clean it up, before it gets completely full. Nothing is worse then frankly deletely files because you need to free up space. Hopefully after this guide, you can safely manange your harddrive with the help of scripts and automation
Anywho here goes:
firstly to check the usage of your harddrive you can use the command:
Code:
$>df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 4.4G 3.4G 764M 82% /
/dev/hda1 14G 4.5G 9.3G 33% /mnt/win32
the -h switch is to change from kilobytes to Gigabyte or megabytes depending on the situation.
As you can see my hda3 is at 83% (haha). With the help of scripts you can have this task done at particular times and email you if its over a certian limit.
First we will make a basic bash script that will report if any paritions are over 80%.
Code:
#!/bin/bash
df -h | grep [89][0123456789]%
The grep [89][0123456789] will grep if any partion is between 80 and 99 exclusively. I didn't include 100% because I don't know how to do it. If anyone knows please let me know
Now you are probably think, wouldn't it be great to have this run at a specifc time everyday? Well...with crontab it is possible.
type crontab -e to start an empty file where you can add all your cron jobs. (for more info type man 5 corntab)
Now to make a basic cron job that will run everyday at 10p.m..
Code:
22 0 * * * df -h | grep -e "[89][0123456789]\%"
The first 22 is the hour the job will accur,
The second 0 is the minute,
The next three *'s are day of month, the month, and day of week respectively
Also we need to use the -e switch, after grep, to tell cron that we want it to intrepet just like the bash shell. Also \ slash tell cron to not intrepret the % sign into anything else.
Finally to have this cron job email you if anyone of your partition's are 80% or more full you need to add the mail command, like so:
Code:
22 0 * * * df -h | grep -e "[89][0123456789]\%" | mail -s "Warning..." you@emailaddr.com
The -s is for subject and
you@emailaddr.com will be replaced by your email address.
Lets me know about this guide. If you like it, or if it wasn't useful. Any feedback is greatly encouraged. Thanks