Help with a filesystem monitoring script.

I'd like to create a cron script that checks filesystems. For example if it reaches 95% USED, I'd like it to send me an email. Can this be possible for up to say 4 filesystems using the df -k command? Any samples to get me started would be much appreciated.

Search the forum and I am sure you will find many..

To get you started, here is a simple logic

ds=$( df -k | grep "filesystem" | awk '{print $5}' | sed 's/%//g')
if [ $ds -gt 90 ];
then
echo "exceeding"
mailx -s "FS Report" abc@dot.com ....
else
echo "fine"
fi

cheers,
Devaraj Takhellambam

Thanks, I tried to look but maybe my search string wasnt accurate.
Is there a way to use case logic? To maybe add a few filesystem checks?

Anyone know why this kicks out after the first check? I'd like it to continue to the next check regardless? Any input would be appreciated.

ds1=$( df -k | grep /dev/filesys1 | awk '{print $4}' | sed 's/%//')
if [ $ds1 -gt 75 ];
then
echo $ds1
echo "filesys1 exceeding"
continue
fi
ds2=$( df -k | grep /dev/filesys2 | awk '{print $4}' | sed 's/%//')
if [ $ds2 -gt 75 ];
then
echo $ds2
echo "filesys2 exceeding"
fi

Eventually I'd like to add more filesystems to check, but cant understand why it kicks out after first check and just displays:

78
filesys1 exceeding

And I know the 2nd check is exceeding as well.

Try this

df -k | awk '$6 ~ /filesys1/||/filesys2/{print $5,$6}' | sed 's/%//g' | while read pct fs
do 
if [ $pct -gt 75 ]; then 
echo "exceeding FS for $fs: now at $pct%"
fi
done

cheers,
Devaraj Takhellambam

@NycUnxer

Is the "continue" line in your script causing it to stop early? Is it correct for it to be there?

Its not necessary, was just trying different things.

Thanks for your suggestion. My tests seemed to work. I was able to add about 4 more filesystems to this cron job script and an email alert when it reaches the thresh hold.