Javier Elices Javier Elices - 3 months ago 47
Perl Question

Running a Perl script from crontab when you use Perlbrew

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

# echo $PERL5LIB

Then, at the crontab file of the user, do something like:

MAILTO=<my email address for the jobs output>

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
. 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
will install under
when you are using
unless you explicitly tell them to do otherwise. Also
seems to be better suited to working along with Perlbrew.

Answer Source

The shebang (#!) line of the script should point to the (perlbrew-installed) perl it is meant to run under. (This should be done as part of installing the script.) That's all you need.

0 2 * * * /path/to/script arg1 ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download