#!/bin/bash # this is a script that warns root about disk partitions reaching the limit HOSTNAME=`hostname` # this constant is the max disk usage for a partition DISK_LIMIT=90 cd df -h |awk {'print $1"\t"$2"\t"$4"\t"$5"\t"$6'} > /tmp/df.$$ # number of total partitions we have is LINES-2 LINES=`wc -l /tmp/df.$$|awk {'print $1'}` for ((i = 2;i <= $LINES;i++)) do DISK_SIZE=`head -$i /tmp/df.$$ | tail -1 | awk {'print $4'} | sed 's/\%//g'` if [ $DISK_SIZE -ge $DISK_LIMIT ]; then MOUNT_POINT=`head -$i /tmp/df.$$ | tail -1 | awk {'print $5'}` PARTITION=`head -$i /tmp/df.$$ | tail -1 | awk {'print $1'}` echo "$PARTITION ($MOUNT_POINT) is $DISK_SIZE% full" >> /tmp/mail_disksize fi done # test if /tmp/mail_disksize is not empty if [ -s /tmp/mail_disksize ]; then mail -s "Warning! Disk partition almost full on $HOSTNAME" varinder@canaca.com, syed@canaca.com, peter@canaca.com < /tmp/mail_disksize fi # remove any temp files rm -f /tmp/df.$$ rm -f /tmp/mail_disksize