Results 1 to 5 of 5
Hi,
I stumbled upon a script on the internet that monitors disk space and if it reaches a certain percentage being full it send an email. However, the problem I ...
- 03-13-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
Scripting help...monitoring disk space..please
Hi,
I stumbled upon a script on the internet that monitors disk space and if it reaches a certain percentage being full it send an email. However, the problem I encountered was that one of the file system names are longer than usual so it expends over to the other columns and causes the other data to be put onto a second line. So the script no longer works when this is the case. does anyone know how to fix the script to take this into account?
This is what I get when I run df-H. The first line goes onto a second line because of the file name so the script return incorrect information when I ask to print columns 5 and 1.
Code:Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 77G 8.2G 65G 12% / /dev/sda1 104M 14M 86M 14% /boot none 525M 0 525M 0% /dev/shm
This is the script I'm using.
Code:#!/bin/sh df -H | grep -vE '^Filesystem|none|cdrom' | awk '{ print $5 " " $1 }' | while read output; do #echo $output usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) partition=$(echo $output | awk '{ print $2 }' ) if [ $usep -ge 10 ]; then echo "Running out of space \"$partition ($usep%)\" on $(hostname)" | mail -s "Alert: Almost out of disk space $usep" some@someone.net fi done
- 03-13-2008 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try this:
RegardsCode:df -H | grep -vE '^Filesystem|none|cdrom' | awk ' NF<5{getline} $5>"10" && NF>5 {print "Running out of space "$1 " on "$5}'
- 03-13-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
I just tried your code, and it seems like it just skips the first line if it's too long. On my file system I have an Use% of 12, 14, and 0 but when I run your code I just get the second file system printed out: "Running out of space /dev/sda1 on 14%"
I would like it to determine that /dev/mapper/VolGroup00-LogVol00 and /dev/sda1 are low on disk space for this example...
- 03-13-2008 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
Change 'df -H' to 'df -HP' and see if that helps.
Vic
- 03-13-2008 #5Just Joined!
- Join Date
- Mar 2008
- Posts
- 6


Reply With Quote
