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.
This is the script I'm using.
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
Comment