Bash Script to Monitor Space by Directory.

Dennis Antle dennis_antle-FFYn/CNdgSA at public.gmane.org
Thu Dec 10 17:29:20 UTC 2009


Thanks Neil,
Nice script.
I can use this script too, but it don't help me with my current issue.
Basicly I need to compare directory size between today and yesterday.
So if a folder grows by more than a GB lets say, then I can have the script send me an email notification. You can see what I have so far in one of my previous emails.



--- On Thu, 12/10/09, Neil Brown <brownn0-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:

> From: Neil Brown <brownn0-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>
> Subject: Re: [TLUG]: Bash Script to Monitor Space by Directory.
> To: tlug-lxSQFCZeNF4 at public.gmane.org
> Received: Thursday, December 10, 2009, 10:32 AM
> 
> 
> 
> 
>  
> 
>  
> I had this old script from work kicking
> around.  It
> lists the largest n files in each directory in the
> specified path.  It
> was originally written for Korn shell, but is ok for bash.
> 
> 
> 
> lm -h will give a brief usage message.
> 
> lm -5 /home will give the 5 largest files in each directory
> in /home,
> etc.
> 
> 
> 
> 
> 
> #!/bin/bash
> 
> 
> 
> #d list largest [-n] files in each directory in path
> 
> 
> 
> # defaults:
> 
> 
> 
> #    -n     1
> 
> #    -s     1 block (
> 1024 bytes per block )
> 
> #    [path] . ( current directory )
> 
> 
> 
> USAGE="usage: lm [ -n n ] [ -s n ] [path]"
> 
> 
> 
> # default parameters
> 
> 
> 
> nh=1;                  
> # number of files
> 
> MAX=`expr 1 \*
> 1024`           
> # max size of file
> 
> spath=".";             
> # specified path
> 
> 
> 
> # command-line parameters
> 
> 
> 
> while getopts hn:s: c
> 
> do
> 
> case $c in
> 
>     h)  usage $0
> $USAGE;           
> # display help text
> 
>     exit ;;
> 
>     n)  nh=$OPTARG;;
> 
>     s)  MAX=`expr $OPTARG \*
> 1024`;;
> 
>     ?)  usage $0 $USAGE;
> 
>     exit 1;;
> 
> esac
> 
> done
> 
> 
> 
> shift `expr $OPTIND -
> 1`;       # search path
> 
> 
> 
> if [ $# -eq 1 ]
> 
> then
> 
>     spath=$1;
> 
> fi
> 
> 
> 
> (
> 
> 
> 
>  # for i in ( all dirs )
> 
> 
> 
>  for i in `ls -FR $spath 2> /dev/null | sed -n
> 's/:$//p'`
> 
>  do
> 
> 
> 
>      c=`ls -l $i | sort -r -n +4 -5 |
> head -1 | awk '{ print $5; }'`;
> 
>      if [ "$c" -gt $MAX ]
> 
>      then
> 
> 
> 
>      for j in `ls -l $i | awk -v
> max=$MAX '$5>=max { print $NF; }'`
> 
>      do
> 
>          ls -l
> $i/$j;
> 
>      done
> 
> 
> 
>      fi
> 
> 
> 
>  done
> 
> 
> 
>  ) 2> /dev/null | pg;
> 
> 
> 
> I hope this helps.
> 
> 
> 
> 
> 
> Neil Brown        brownn0-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
> 
> 
> 
> Toronto, Ontario, Canada
> 
> 
> 
> 
>  
> 
> 


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list