AWK question (again)

From: F. Winter <winter_at_PHYSnet.uni-hamburg.de>
Date: Tue, 29 Aug 2000 15:36:02 +0200 (MET DST)

Thanks to all responders so far. The first answer came
just one minute after posting the question. And the solution
was really with just a whitespace to combine two strings.
Like a=b c

But unfortunatly this is only a f**ing small piece in
the solution of my problem I am on since yesterday.

This is my real intention:

I have to change the group ownership for every file in a
given directory and its subdirectories if it has not already
this groupownership. But before a group ownership is changed
I have to check the if the groupquota for this group is full.
If so do not change the group just leave it untouched.

The problem is solved this the script below:
But a problem occured with extra letters like brackets ( ).
And the biggest problem with german \204 which is an a with
two points on top. These files cause errors. They are
created from users using Windows and an imported samba drive. MS! :(

Do you know a better and/or more stable solution to this maybe
common problem in UNIX.


Thank you



#!/PHYSnet/share/bin/perl

sub kk {
    while (substr($txt,length($txt)-1,1) eq " ") {
        $tmp=substr($txt,0,length($txt)-1);
        $txt=$tmp;
    }
}

sub checkme {
    $ende=0;
    while (<PIPEDIR>) {
        if ($ende==0) {
            $txt=$_;
            $txt =~ s/\n//g;
            kk;
            $d3=$txt;
            open (PIPEDIR2,"find $verz -name \"$d3\"|");
            while (<PIPEDIR2>) {
                $datei=$_;
                $datei =~ s/ /\\ /g;
                if ($ende==0) {
                    print "Trying ";
                    print $datei;
                    open(TESTPIPE,"quota -g $group|grep \"*\"|");
                    if (<TESTPIPE>) {
                        print "quota voll!\n";
                        $ende=1;
                    } else {
                        print "chown ";
                        open(CMDPIPE,"|chown nobody $datei");
                        print "chgrp ";
                        open(CMDPIPE,"|chgrp $group $datei");
                        print "chmod ";
                        open(CMDPIPE,"|chmod 070 $datei");
                        print "\n";
                    }
                }
            }
        }
    }
}


sub check{
    $verz=$_[0];
    $group=$_[1];
    print "Checking $verz for $group\n";
    open(PIPEDIR,"ls -Rl $verz|grep -v $group|grep \" \"|awk -F\" \" \'\{print \$9\,\$10\,\$11\,\$12\,\$13\,\$14\,\$15\}\'|");
    checkme;
}

check("/PHYSnet/users/groups/group-las_a/","gr-las_a");






--
 Frank Winter          Tel.: +(49)-40-42838-2404
 PHYSnet RZ            Email: winter_at_PHYSnet.uni-hamburg.de
 Uni Hamburg           
 Jungiusstr. 9
 D-20355 Hamburg       
Received on Tue Aug 29 2000 - 13:37:23 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:41 NZDT