Hey i'm new to writing shell scripts and I'm trying to write a script that checks how full my disks are and notifies me when they are above 90% full. The problem i'm having is that one of the Filesystem is long enough that it is moves into the next colum of output from df there by forcing the rest of the information to the next line and throughing off what information I'm pulling out of it. I was wondering if there was any way around this problem.
Below is the script I'm using:
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|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 90 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep%"
myemailaddress@somewhere.com
fi
done
The output for df looks something like this
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 3.9G 15G 21% /
/dev/mapper/vg_data-lv_home
1.4T 1.3T 74G 95% /home
The last two lines on the output of df are the lines that are giving me trouble.