Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I constantly have to set up new servers for an employer of mine for an exact purpose of his, and as such they all have to be set up in exactly the same way. So I've created a script in PHP that I run from my own box to automatically send over all the relevant files, compile everything, run updates, and everything else.

However, for some reason these brand new servers come with perl, which is fine, but they have perl installed in different locations. This makes it a pain for me to copy over Config.pm for CPAN without going in and finding the location manually.

Is there perhaps some command I'm unaware of that will hunt down the precise location?

If it helps, usually the servers are CentOS 5

share|improve this question

4 Answers 4

up vote 3 down vote accepted

Use the which command to get the path of perl:

which perl


Use the find command in linux to look for CPAN:

find / -name CPAN.pm
share|improve this answer
    
Oh, very fancy. Is there a way I can also make it exclude the filename? i.e. return /usr/share/perl5/ instead of /usr/share/perl5/CPAN.pm? If not, no problem; I can pull it out in PHP, but if so, that'd be a lot easier –  Rob Jun 4 '12 at 15:44
2  
Try this: find / -name "CPAN.pm" -exec dirname {} \; | sort -u –  에이바 Jun 4 '12 at 15:49
    
That's perfect! Thanks a lot! –  Rob Jun 4 '12 at 15:52
type -P perl

will find the location of Perl in the path.

If mlocate.db is up to date, you can use

locate CPAN.pm

Another way to find likely locations for CPAN.pm:

perl -le '$,="\n"; print @INC'
share|improve this answer

I constantly have to set up new servers for an employer of mine for an exact purpose of his, and as such they all have to be set up in exactly the same way. So I've created a script in PHP that I run from my own box to automatically send over all the relevant files, compile everything, run updates, and everything else.

You're doing it wrong and making more work for yourself.
Investigate configuration management tools (Puppet, Chef) or deployment tools (radmind) -- If you deploy your systems with something like the tools I just mentioned you will know that every box is truly identical, and more importantly that they'll be kept that way.


Until you have the time to do that, locate or find as others have mentioned will at least tell you where the file you want lives.

share|improve this answer
    
I absolutely appreciate it, and I'll certainly look into them when I have the time. Thank you. –  Rob Jun 4 '12 at 16:07

Faster than Ava Gailliot's suggestion and with fewer false positives:

find $(perl -E 'say"@INC"') -name CPAN.pm -exec dirname {} \;

The path here is all the directories of your perl installation where perl is allowed to look for modules to load.

share|improve this answer
    
Unrecognized switch: -E (-h will show valid options). –  Rob Jun 5 '12 at 14:46
    
Sorry about that. -E option was introduced with Perl v5.10. You can say perl -e 'print"@INC"' instead. –  mob Jun 5 '12 at 15:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.