Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

admin script help

by mhearse (Hermit)
on Sep 30, 2003 at 06:13 UTC ( #295191=perlquestion: print w/ replies, xml ) Need Help??
mhearse has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with a machine that has a problem with the ownership of symlinks. I need to search the entire directory tree for symlinks. Then, if they are owned by a specific user, change the user and group. Then I want to echo the full path to the symlink changed. This machine is using Perl 4, so I don't think modules are an option. I'd appreciate any help/suggestions.
chomp (@files = `ls -R /`); #Is there a better way to #find all symlinks on system? foreach $x (@files) { if (-l $x && -o $x) { #How do I test for ownership chown (1234, 35, $x); #of a specific user? print "Changed $x\n"; #How do I print the full path? } }

Comment on admin script help
Download Code
Re: admin script help
by ehdonhon (Curate) on Sep 30, 2003 at 06:17 UTC
    File::Find has a neat utility called 'find2perl'. Take a few minutes to learn that, and it will write 90% of your script for you.

    update I missed the part about using Perl 4 when I read your post the first time. If the File::Find module is out, then how about just opening a pipe from the "find" command?

Re: admin script help
by Juerd (Abbot) on Sep 30, 2003 at 07:00 UTC

    This machine is using Perl 4

    Wow, ten year old software still in use. May I ask why?

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: admin script help
by Abigail-II (Bishop) on Sep 30, 2003 at 07:34 UTC
    If all you have is perl4, you might as well use a shell one-liner. Something like the following ought to do:
    find / -type l -user "olduser" -exec chown "newuser:newgroup" {} \ +;

    Abigail

Re: admin script help
by aquarium (Curate) on Sep 30, 2003 at 12:54 UTC
    you should check if each file/symlink you find to see if it's a symlink or file, if you want to change the ownership of the symlink itself, as this is done with "chown -s symlink_name" ..otherwise a usual chown only changes the ownership of the file pointed to by the symlink.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://295191]
Approved by ehdonhon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (18)
As of 2014-12-19 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (90 votes), past polls