LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Feedback on a script (https://www.linuxquestions.org/questions/linux-general-1/feedback-on-a-script-784615/)

kaplan71 01-25-2010 10:38 AM

Feedback on a script
 
Hi there --

I am writing a script, based on one from an older UNIX reference guide, that is meant to check the size of a series of folders, and if any exceed a defined size, the administrator will be notified via e-mail.

The syntax of the script is currently the following:

Code:

#!/bin/bash
# check folder size

clinics='ls -1 /CMS/xiodata'
limit=80000

for clinic in $clinics
do
        diskuse='du -hcs /CMS/$clinics  | awk '{print $1 }' -`
        if [ $diskuse -gt $limit ]
        then
                /bin/mailx -s Clinic Folder Size admin@company.com <<!

System Administrator --

The folder size of the $clinic is over the $limit. Investigate the matter
further to determine what steps need to be done to correct this issue.

!
        fi
done

I had some questions that hopefully I could get feedback:

1. The limit= line sets the amount 80000 blocks. What would the syntax be to set the amount to 400 gigabytes.

2. Should the clinics= line read as-is, or should the syntax be the following:

Code:

clinics='ls -lh /CMS/xiodata'
Thanks.

bmxcess 01-25-2010 05:26 PM

Sorry, should not have replied so quick [EDIT]

Perhaps a perl script would be better suited for your task? ie:

#!/usr/bin/perl
open( PIPE, "du -hcs /CMS/$clinics|" ) or die "Couldn't read pipe: $!";
while ( <PIPE> ) {
my( $f1, $f2 ) = split ' ', $_;

if($f1 =~ /G/) {
# do something with gigs
}
if($f2 =~ /M/) {
# do something with megabytes
}

}
close(PIPE);


All times are GMT -5. The time now is 11:31 AM.