Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help! script needed to give mail alert on disk space. (ksh)

Status
Not open for further replies.

rik1551

IS-IT--Management
Sep 14, 2001
10
GB
Hi,

I'm no script writer but I have been given the task of monitoring certain filestores for remaining capacity.
Instead of logging onto the box everyday and doing a df -k I would like a script that could do this for me and alert me by email if any of the disk areas are more than 80% full.
Has anybody written such a script? or can anybody point me in the right direction?
All help would be much appreciated!

Thanks
 
Lot of people asking that question at the moment. Here's a script called df.sh which takes df -k output (on Solaris) and reports a warning for file system where usage is over 80%.

#!/bin/ksh
# df.sh - report on df -k usage over 80%
clear
echo " Checking File Systems"
echo
echo "Mount Total Used Free Used% Test"
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
df -k |grep /| awk '{$2 = $2 /1000; $3 = $3 /1000 ; {if ($5>80 || $5=="100%") $
9 = "warning"}; $4 = $4 /1000; printf "%-15s " "%8.1f Mb " "%
8.1f Mb" "%8.1f Mb\t%5s%10s\n" ,$6, $2, $3,$4,$5,$9}'|sort
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo
echo "Check file systems with warning"
echo

Just create the script above and run it. If you want to mail yourself the results, then you can do df.sh | mail username

If you want it to run automatically, put it in cron.

If you're not running on Solaris, the script will probably require some modification to the awk script.

If you can't do that, why not just create a cron entry which mails you the standard df -k output a couple of times a day?

Greg.
 
Thanks Greg,

Thats exactly what i was looking for!

Richard
 
Greg - you should turn that into a FAQ, I've lost count of the number of times I've seen that question. Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top