Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: Trouble finding modules from cron

by afoken (Chancellor)
on Apr 13, 2017 at 04:30 UTC ( #1187820=note: print w/replies, xml ) Need Help??

in reply to Re: Trouble finding modules from cron
in thread Trouble finding modules from cron

#!/bin/sh perl -I /some/special/libpath:/another/special/libpath "$@"

Drop in an exec to get rid of a needless /bin/sh instance:

#!/bin/sh exec perl -I /some/special/libpath:/another/special/libpath "$@"

And if you have more than one perl, specify which one you want to start. Also do this if you are not sure what $ENV{'PATH'} may contain.

#!/bin/sh exec /usr/local/perl-5.42.99/bin/perl -I /some/special/libpath:/anothe +r/special/libpath "$@"

But then again, cbeckley++ is right, perl can do fine without a shell:

#!/usr/local/perl-5.42.99/bin/perl use lib '/some/special/libpath','/another/special/libpath'; # rest of the script here, unmodified

Perl does not even mind if you prefix those two lines to an existing script, the shebang (#!) line of the existing script will be parsed as a comment.

If you don't want to modify scripts, you can also use a perl script as a wrapper:

#!/usr/local/perl-5.42.99/bin/perl use lib '/some/special/libpath','/another/special/libpath'; require '/path/to/real/';


This simple one assumes that returns a true value. Alternatively, use do $filename, but that needs more code for error handling:

#!/usr/local/perl-5.42.99/bin/perl use lib '/some/special/libpath','/another/special/libpath'; unless (defined(do '/path/to/real/')) { die "Could not parse script: $@" if $@; die "Could not read script: $!"; }


Generally, if you run a script as root or setuid root, consider adding -T to the shebang line to enable taint mode (see perlsec).


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1187820]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2023-12-11 13:11 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.