Bash Script to Monitor Space by Directory.

Dennis Antle dennis_antle-FFYn/CNdgSA at public.gmane.org
Thu Dec 10 16:59:57 UTC 2009


Thanks Kevin,
I'm currently using cron to dump the results of du into a text file each night. Format of the text file is   

size    /directory/path
size    /directory/path/subdir/

Where I run into trouble is when compareing yesterdays text file to todays to detect if a directory has grown by over a GB. If a directory has grown more than a GB then I want the script to email me.

I have a working script, but it takes to long to process on large volumes. So what I need is an efficient way to loop through the lines in the text files.


FILE2=$(date --date="1 days ago" +%Y%m%d).arc
showopts () {
  while getopts ":pq:" optname
    do
      case "$optname" in
        "f")
            FILE2=./$OPTARG
          ;;
        *)
        # Should not occur
          echo "Unknown error while processing options"
          ;;
      esac
    done
  return $OPTIND
}
FILE=$(date +%Y%m%d).arc
declare growth=0
while read line1;
do
        size1=`echo $line1 | sed 's/\s.*//'`
        dir1=`echo $line1 | sed 's/\S*\s*//'`
        while read line2;
        do
                size2=`echo $line2 | sed 's/\s.*//'`
                dir2=`echo $line2 | sed 's/\S*\s*//'`
                if [ "$dir1" = "$dir2" ];
                then
                        growth=`expr $size1 - $size2`
                        if [ $growth -ge 1000 ];
                        then
                                echo $dir1 " |growth:" $growth
                        fi
                fi

        done < $FILE2
done < $FILE



 
--- On Wed, 12/9/09, Kevin Cozens <kevin-4dS5u2o1hCn3fQ9qLvQP4Q at public.gmane.org> wrote:


From: Kevin Cozens <kevin-4dS5u2o1hCn3fQ9qLvQP4Q at public.gmane.org>
Subject: Re: [TLUG]: Bash Script to Monitor Space by Directory.
To: tlug-lxSQFCZeNF4 at public.gmane.org
Received: Wednesday, December 9, 2009, 3:54 PM


Dennis Antle wrote:
> So I need to develop a bash script to monitor changes in size by directory, on the SAN volume.
> I'm looking for advise as to how to go about this? 

You could use the du command to get the information you need.
--
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



      __________________________________________________________________
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail.  Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca
--
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