I have tried the following and find it to work. This is done with a non-privileged user. First find out where your perl command is:
# which perl
Then check the value of PERL5LIB
:
# echo $PERL5LIB
Then, at the crontab file of the user, do something like:
MAILTO=<my email address for the jobs output>
HOME=/home/myhome
PERL5LIB=/home/myhome/perl5/lib/perl5
0 2 * * * $HOME/<rest of path to perl>/perl $HOME/<path to my perl script> arg1 ...
This will run a job at 2am and seems to find all Perl libs correctly. My question is: is this complete and portable? Is there a better way?
I have seen a number of bash and perl scripts out there that are supposed to prepare the environment for the execution of a Perl script, but this seems to suffice. Any advice will be welcome!
EDIT: From the comments to the question, it seems that I am using a "bad" mixture of Perlbrew and local::lib
. The way to make sure libraries get installed inside a particular Perlbrew version is answered here: How do I install CPAN modules while using perlbrew?. Both cpan
and cpanm
will install under PERL5LIB
when you are using local::lib
unless you explicitly tell them to do otherwise. Also cpanm
seems to be better suited to working along with Perlbrew.
perlbrew use
seems to exec into a new shell, so you'd need to pipe commands into it:perlbrew use perl-5.26 <<<'perl ./some-script.pl'
(Bash syntax).perlbrew exec --with perl-5.26 'perl ./some-script.pl'
would be equivalent, but prints an annoying header before the output. – Aaraperlbrew
, so you shouldn't be settingPERL5LIB
. – GilbertinePERL5LIB
I only get some of the@INC
directories in the running Perl script and thenuse
will not consider certain libraries ending up in a compile-time error. – Invadecpanm <module>
to install modules and they end up in thePERL5LIB
directory.cpan
seems to do the same. Are you suggesting that they should be installed for each specific Perl version? I am using Perlbrew to have a local Perl (and libraries) for a user, not to use more than a single Perl version, so I was not paying attention to the place libraries were going. – Invadelocal::lib
is meant to have libraries local to a user but with the system-wide Perl. Perlbrew is meant to have a whole Perl + libraries environment local to a user. Am I right? But do you see a problem if I stick to a single Perlbrew interpreter? It would take some effort to go back... – Invade--quiet
. I use it in some off my~/.bash_prfofile
aliases that require some perl modules. But I do not want to clutter my installed Perls likealias minidoc='perlbrew exec --quiet --with perl-5.26.1@minicpan mcpandoc -MPod::Text::Color::Delight'
– Nettienettingsource
d at shell startup. You're describing the backup behaviour when that isn't done. – Gilbertineperl
, and you'll need to upgrade eventually. – Gilbertinelocal::lib
so itsPERL5LIB
variable points to a directory of this user and then Perlbrew to have a different Perl version than the system´s one. The libraries get installed under thePERL5LIB
directory which is local to the user. Thecrontab
file I refer to is also the user´s. – Invadeperl
a user would only use was a specific one installed usingperlbrew
. I said I don't believe you can guarantee that. Lots of stuff use the systemperl
. – Gilbertineperl
installed in their home dir]", I know that. They shouldn't be using local::lib. local::lib is a hack whose need was eliminated by the installation of aperl
to which they have full access. – Gilbertinecpan
andcpanm
install underPERL5LIB
by default when you havelocal::lib
. Fixed in the question. Thanks. – Invade