2

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

4 Answers 4

5

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
2
  • 1
    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, 2012 at 15:44
  • 2
    Try this: find / -name "CPAN.pm" -exec dirname {} \; | sort -u
    – 에이바
    Jun 4, 2012 at 15:49
5
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'
4

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.

1
  • I absolutely appreciate it, and I'll certainly look into them when I have the time. Thank you.
    – Rob
    Jun 4, 2012 at 16:07
1

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.

2
  • Unrecognized switch: -E (-h will show valid options).
    – Rob
    Jun 5, 2012 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, 2012 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .