Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I want to write a script which basically monitors the amount of file usage (%) for a specific file system ,say "/mount1" for a amount of %,say 98%...When it reaches this %,it should generate a warning email to increase the disk space..
And this script should run once everyday at a specific time in unix.
Thanks for your help.Best Regards,
Dev

Here's one that I use for filesystem monitoring. You can modify it to do email alerts if you want.
Here is the config file called diskspace.tab:
# D I S K S P A C E . T A B
#
# Lookup file for the 'diskspace.sh' program.
# Format: <filesystem> <flag_percent> <alarm_percent>
#
/ 80 90
/var 30 40
/opt 90 97
/usr 90 95
/tmp 70 90
/stand 80 95
/home 80 95---------END of DISKSPACE.TAB
Here is the script diskspace.sh:
# set -x
# D I S K S P A C E . S H
#
# 07/02/96
#
# Checks available disk space against a reference table,
# and flags the filesystems that are below their limit.
## 10/12/94 Original Version
# 03/06/96 Minor modifications for HP/UX 10.0
# 07/02/96 Fixes to handle multi-line bdf lines better
TABLE=/diskspace.tab
BOLD=`tput smso`
NORM=`tput rmso`if [ ! -f $TABLE ]
then TABLE=./diskspace.tab
echo "Using Table file : "$TABLE
fiecho "\n\n\n% Used\tWarn\tFilesystem Name\t\t\tCURRENT DISKSPACE STATUS"
echo---"bdf | while read LINE
do
set x ${LINE}
if [ -n "$3" ] # If $3 is null, suspect multiline fs
then
shift 5
else
read LINE
set x ${LINE}
shift 4
fiif [ -n "$1" -a "$1" != "used" ]
then
PERCENT=`echo $1 | tr -d '%'`
FILESYSTEM=$2set x `grep "^${FILESYSTEM} " ${TABLE}` # tab aftr FS
if [ -z "$3" ]
then
continue
fi
MAX=$3
ALARM=$4
if [ -z "$4" ]
then
ALARM=100
fi
if [ ${PERCENT} -gt $MAX ]
then
HDR=${BOLD}
TRL=${NORM}
if [ ${PERCENT} -gt $ALARM ]
then
TRL="$TRL\t\t\t\t*** CRITICAL ***"
else
TRL="$TRL\t\t\t\t*** WARNING ***"
fi
else
HDR=""
TRL=""
fiecho "${PERCENT}%\t(${MAX}%)\t${HDR}${FILESYSTEM}${TRL}"
fi
doneecho "\n"
exit 0
--------End of DISKSPACE.SH

e.g. for /dev/hdb9
df -h |grep /dev/hdb9|awk '{ print $5 }'or its mount point (/mnt/hdb9)
df -h |grep /mnt/hdb9 |awk '{ print $5 }'

Hi Googly and Dlonra,
Thank you so much for you quick response and help.I will schedule it and will let you know what I get.
Once again.Thanks a ton!!Regards,
Dev

Hi Googly,
Thanks once again.I need some more help.
Since I am on the learning process,I find it a little tough to exactly understand the sequence/flow of this script.
Can you explain me a little bit about this config file.And I would appreciate if you can explain me what exactly is going on in each step.especially the lines like:TABLE=/diskspace.tab
BOLD=`tput smso`
NORM=`tput rmso`
And how do I make it run this script daily for once using crontab...
Thank you so much..
Regards,
Dev

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |