Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

admin script help

by mhearse (Chaplain)
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? } }

Replies are listed 'Best First'.
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 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" {} \ +;


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 => '', plp_site => '', do_not_use => 'spamtrap' }

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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2016-10-22 06:56 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (292 votes). Check out past polls.