Skip to content
Advertisement

Why does a Perl script run during boot on CentOS not find certain modules?

I am currently trying to run a perl script at boot in a custom version of CENTOS.

I am doing so by calling it from an rc1 script, the call looks like this:

/mydirectory/myscript &

But I’m getting the error “Can’t locate strict.pm in @INC”

This isn’t specific to strict.pm, it throws that error at for whichever module is first on the use list. When I run the same command from the shell, however, it runs no problem.

So why is it that my perl script cannot find the modules during bootup?

Advertisement

Answer

Maybe the @INC, which comes from the environment, has not been built up. It needs the paths to its libraries.

You can either call it explicitly with the perl interpreter and the -I option, or set the PERL5LIB environment variable.

PERL5LIB='/usr/lib/perl5' /mydirectory/myscript &

If there are several folders, separate them with a colon :.

 PERL5LIB='/usr/lib/perl5:/tmp:/etc/lib/perl5' /mydirectory/myscript &

Please note that I don’t know where the lib dir is in your CentOS, so I made that path up.

You can find out by printing @INC from a regular shell like this:

$ perl -E 'say for @INC'

Append all the paths it lists to the environment variable for the call you make in your rc1 script and it should work.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement