The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to monitor files in a directory and sending the alert shellscripter Shell Programming and Scripting 0 11-26-2008 02:26 AM
Monitor your network with GroundWork Monitor Community Edition iBot UNIX and Linux RSS News 0 10-08-2008 11:40 AM
script to monitor directory nulinux Shell Programming and Scripting 17 08-22-2008 10:28 AM
Hep with script to monitor directory cmf00186 UNIX for Dummies Questions & Answers 2 10-25-2006 02:42 PM
Monitor which users enter my home directory mnpradeep High Level Programming 1 03-21-2002 05:08 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-01-2009
LRoberts LRoberts is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 87
Question Monitor capacity of directory

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
  #2 (permalink)  
Old 06-01-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Code:
alert=80
partition=/lcl/prd/apps/Tivoli/playground

df -hl "$partition" | {
 read ## discard header
 read fs size used available percent mount
 if [ ${percent%?} -gt $alert ]
 then
   host=$(hostname)
   date=$(date)
   fmt='Running out of space "%s (%s)" on %s as on %s\n'
   printf "$fmt" "$partition" "$percent" "$host" "$date" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
 fi
}
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0