Script to check disk space in Linux
Posted by raxsoNov 24
Here’s a simple shell script that will check the available disk space on the root filesystem and send an e-mail message if the used space is at 90% or more.
#!/bin/bash
# monitor available disk space
SPACE=`df | sed -n ‘/\/$/p’ | gawk ‘{print $4}’ | sed ’s/%//’`
if [ $SPACE -ge 90 ]
then
echo “Disk space on root at $SPACE% used” | mail -s “Disk warning” email@example.com
fi
you can set the shell script to execute at a set number of times to monitor the disk activity. You can do this using the cron. For a low-volume file server, you may only have to run the script once a day:
30 0 * * * /usr/local/scripts/diskmon
For a high-volume file server environment, you may have to monitor this every 30mins.
Like this blog? Why not buy me a cup of coffee?/30 * * * * /usr/local/scripts/diskmon





![[hackers black book]](http://raxso.net/images/hbb-ani-misuse.gif)





Great little blog you’ve got here - keep up the good work. Patch.
[Reply]