on Mon, 10 Jun 2002 12:21:24 GMT, [EMAIL PROTECTED] (William
Melanson) wrote: 

> #!/usr/bin/perl -w
As  Sudarsan already mentioned: 'use strict;' here. (Not using strict 
is like forgetting to take your light sabre :-)

> system("/usr/bin/clear");
> @arg1 = qw(
>       mail
>       sysquota
>       root
>       nobody
>       smmsp
>       daemon
>       testing
> );

> 
> unless (open(RQUOTA,"/usr/sbin/repquota -a |"))  {
>        print("Unable to open repquota file:\n");

Nothing is going to happen if you can't run the 'repquota' command, 
so I would use

    open (...) or die "Cannot fork: $!";

here. Also note the use of the '$!' variable, which (should) give you 
a helpful error message.

> } else {
>        if (-e "/tmp/stat.tmp") {
>           unlink("/tmp/stat.tmp");
>        }
>        print("Users Without Quotas * * * *\n\n");
>        while (<RQUOTA>)  {
>              if (/\s0\s{7}0\s{1,}/) {

In my opinion, you are trying too hard here with a regex. I would use 
'split'.

>                 for ( $i = 0; $i <=6; $i++ )  {

You are hardwiring the size of your '@arg1' array here. Instead of 
'6', you should at least use 'scalar @arg1'. Better yet, use the more 
Perl-like

    for my $user (@arg1) {...}

>                       s/\b$arg1[$i]\b\s{0,}\-\-\s{0,}[0-9]{1,}.*$//
>                       g; 
>                 }

Again, regex to complex in my opinion.

>                 if (/^[a-zA-Z0-9]/)  {
>                    print("$_");
>                 }

This could be written as

                print if /^[a-zA-Z0-9]/;

>                 if (/(\w+)/)  {
>                    unless (open(NQUOTA,">>/tmp/stat.tmp"))  {

You are potentially reopening this file before it is closed. Perl 
will not complain about this.

>                           print("Unable to open /tmp/stat.tmp
>                           file:\n"); 
>                    } else {
>                           print(NQUOTA "$1\n");
>                    }
>                 }
>              }
>        }

To print out those users that have 0 for both soft and hard 
block limits, I would use:

#!/usr/bin/perl -w
use strict;

while (<DATA>) {
        next unless /--/; #skip headers
        chomp;
        
        my ($user, $used, $soft, $hard) = split /[\s\-]+/;
        print "$user\n" unless $hard or $soft;
}
_DATA__
                        Block limits               File limits
User            used    soft    hard  grace    used  soft  hard  
grace
root      --  307828       0       0           2805     0     0       
nobody    --    8628       0       0            179     0     0       
sysquota  --       4       0       0              1     0     0       
Vigart    --    9956   40000   45000            526     0     0       
discount  --  169492  180000  175000           9134     0     0       
peanut    --    5700   40000   45000             96     0     0       
lanio1    --   11544   40000   45000            296     0     0  


-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to