For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2007 > Scan disk for files with certain owner









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Scan disk for files with certain owner
Andreas Moroder

2007-02-28, 3:59 am

Hello,

I need a perl script that runs under linux that should recursively
search the directory tree and print out all the files that have a uid or
gid that does not resolv to a username or userid.

Can anyone give me a hint ?

Thanks
Andreas

Neal Clark

2007-02-28, 3:59 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd use some combination of File::Find with getgrgid and getpwuid
with the wanted callback.

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

use File::Find;

my @directories = ('/dir1','/dir2');

find(\&wanted,@directories);

sub wanted {
my ($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_);
if (!(defined(getpwuid($uid)) && defined(getgrgid($gid)))) {
print $File::Find::name . "\n";
}
}

On Feb 28, 2007, at 12:12 AM, Andreas Moroder wrote:

> Hello,
>
> I need a perl script that runs under linux that should recursively
> search the directory tree and print out all the files that have a
> uid or gid that does not resolv to a username or userid.
>
> Can anyone give me a hint ?
>
> Thanks
> Andreas
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFF5T2VuT/QpFTX5YIRAlJ7AKDQThpftG/RhzKpGjT8bEWSv4S1FgCcCDkJ
l74ux3NssrPN5MuwO2h8YDE=
=0jTF
-----END PGP SIGNATURE-----
John W. Krahn

2007-02-28, 3:59 am

Andreas Moroder wrote:
> Hello,


Hello,

> I need a perl script that runs under linux that should recursively
> search the directory tree and print out all the files that have a uid or
> gid that does not resolv to a username or userid.
>
> Can anyone give me a hint ?


perl -e'exec qw[ find / -nouser -o -nogroup ]'




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Neal Clark

2007-02-28, 3:59 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

or perhaps more to the point
my ($uid,$gid) = (lstat($_))[4..5];

On Feb 28, 2007, at 12:30 AM, Neal Clark wrote:

> sub wanted {
> my ($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_);


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFF5T7aecZZ/ XfYgxIRAuCpAKDKegsQwDEqvSs2QLTrpj4T8Dbnr
QCffRkd
enrJVr5BjKGxEno2du9eWIo=
=ZpA6
-----END PGP SIGNATURE-----
Andreas Moroder

2007-02-28, 6:59 pm

Neal Clark schrieb:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'd use some combination of File::Find with getgrgid and getpwuid with
> the wanted callback.
>
> #!/usr/bin/perl -w
> use strict;
>
> use File::Find;
>
> my @directories = ('/dir1','/dir2');
>
> find(\&wanted,@directories);
>
> sub wanted {
> my ($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_);
> if (!(defined(getpwuid($uid)) && defined(getgrgid($gid)))) {
> print $File::Find::name . "\n";
> }
> }
>
> On Feb 28, 2007, at 12:12 AM, Andreas Moroder wrote:
>

Hello Neal,

It works like a charm.
thank you very much.

Andreas
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com