Good morning.
I have been attempting to find a way to monitor the capacity of a directory so that when it reaches 80% or higher I can send an event.
I was able to find a script that does this for the whole drive by I can not seem to figure out how to do this for just a single directory.
Code:
ADMIN="myemail@someplacecool.com"
# set alert level 90% is default
ALERT=60
df -hl | egrep -ve '/lcl/prd/apps/Tivoli/playground' | 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 $ALERT ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep" $ADMIN
fi
done
As you can see from above I am attempting to get the capacity of /lcl/prd/apps/Tivoli/playground and if its 90% or over then it sends an e-mail.
However when I try this is the results...
Code:
"test.sh" 14 lines, 586 characters
seville:/lcl/prd/apps/Tivoli/playground>./test.sh
capacity Filesystem
./test.sh: line 10: [: capacity: integer expression expected
81% /dev/md/dsk/d10
0% /devices
0% ctfs
0% proc
0% mnttab
1% swap
0% objfs
0% sharefs
0% fd
1% swap
1% swap
67% /dev/md/dsk/d100
I am not very good yet with shell scripting so I am kinda stuck here.
Any help would be great.
Thank you.
-----Post Update-----
Figured it out.
Code:
#!/bin/ksh
space=`df -bhk /lcl/prd/apps/Tivoli/playground | cut -d "c" -f1 | awk '{print$5}'`
capacity=${space%?}
echo $capacity
if [ $capacity -gt 70 ]; then
echo "Getting full! $capacity"
else
echo "Below percent trap."
fi