[Chicago-talk] chown inside a script

Jay Strauss me at heyjay.com
Thu Dec 6 20:23:25 PST 2007


On Dec 6, 2007 9:56 PM, Brian Katzung <briank at kappacs.com> wrote:
> Jay Strauss wrote:
> > On Dec 6, 2007 6:41 PM, Brian Katzung <briank at kappacs.com> wrote:
> >> Jay,
> >>
> >> Here's a rough code snippet to get you started.
> >>
> >> use File::Find;
> >>
> >> # Queue looks like /some/path/closed/user_name/file_name
> >> my $base_dir = '/some/path/closed';
> >>
> >> sub proc_files
> >> {
> >>         return unless (-f $File::Find::name &&
> >>           $File::Find::name =~ m{^\Q$base_dir\E/([^/]+)/([^/]+)$});
> >>
> >>         my ($user, $file) = ($1, $2);
> >>         print "Process file $file in queue for user $user\n";
> >> }
> >>
> >> find({ 'wanted' => \&proc_files, 'follow' => 0, 'no_chdir' => 1 },
> >> $basedir);
> >>
> >>   - Brian
> >
> > Thanks Brian, I'm not exactly sure what the regex does.
>
> It makes sure the current path being examined is the base_dir plus two
> components, remembering those two components (think of it as a path
> check, split, and splice all in one).
>
>  > I don't know
> > wher \Q and \E do, the other part I think is match and remember the
> > directory and filename.
>
> I'm going to make you do *some* work. :-) See man/perldoc perlre.
>
> > Also, I already know where the files are, what's the advantage of
> > using File::Find?
>
> And it's a good thing you know, too, because File::Find doesn't "find"
> files! It's a directory tree iterator, which is exactly what I wanted
> here (with the "filtering" as indicated)--to iterate over each "queued"
> file.
>
> > Jay
>
>   - Brian

Oh, it iterates, makes sense now.  I read the perldoc on File::Find
and paid more attention to what the args of find were for.  Didn't
think about what it returns <dumb>.

    \E		end case modification (think vi)
    \Q		quote (disable) pattern metacharacters till \E

I guess your using that in case the contents of $base_dir contains metachars?

Just to be clear, you're suggesting using a script like something
above, and call it with FAM when the directory changes?

I confused, why would I iterate over the entire directory, when it
looks like FAM can report when a single file is created, and I could
operate on that specific file?

I'm probably missing some important point.

Thanks for all the help.
Jay


More information about the Chicago-talk mailing list