CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: not in @INC



Jun 9, 2016, 2:11 PM

Post #1 of 10 (4750 views) not in @INC Can't Post

I've created a small program to run at system startup.
I'm using Fedora 23 for my operating system, and the program I am starting is run via rc.local.
The program runs fine when started manually as root.
During boot, when rc.local runs my program, I get the following failure:
Can't locate in @INC (you may need to install the DateTime module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/bin/ line 14.

I have searched for and found it in:
/root/.local/share/.cpan/build/DateTime-1.28-78qCSF/lib directory.

How can I get it into @INC ?
Thanks, Tom

Veteran / Moderator

Jun 9, 2016, 3:22 PM

Post #2 of 10 (4747 views)
Re: [Trying] not in @INC [In reply to] Can't Post

If your program runs when started manually, then it means that your environment is functional and your module probably properly installed (and Perl can find it in @INC).

It would seem, therefore, that Perl is probably not yet properly configured when you run it at boot time. I would suggest that you try to launch your Perl program later in the boot process, which presumably means trying to move the launch down toward the end of the rc file. That's just my guess, I have never used Fedora, I have no idea on its boot sequence, there may be some other config files involved in the boot process.


Jun 10, 2016, 3:53 AM

Post #3 of 10 (4741 views)
Re: [Laurent_R] not in @INC [In reply to] Can't Post

The problem is Perl can't find it in @INC because it isn't in @INC.
User root installed the mod via cpan, it ended up in root's directory. Things are fine when root starts the program, but no one else can run the program because DateTime is not in @INC.

How do mods get installed into one of the paths defined in @INC?

Veteran / Moderator

Jun 10, 2016, 7:14 AM

Post #4 of 10 (4732 views)
Re: [Trying] not in @INC [In reply to] Can't Post

I have searched for and found it in:
/root/.local/share/.cpan/build/DateTime-1.28-78qCSF/lib directory.

That is the build directory, not the install directory. You should look again to see where it was installed.

If the script runs correctly when executed manually but not when executed during bootup, then the problem is related to the difference between the user environment vs the system environment.

How are you calling the script from rc.local and are you calling the exact same way when running manually?

Do you have a shebang line in the script pointing to perl or are you relying on the path environment to locate perl?

Are there multiple versions of perl installed on the system?

Please post the beginning of the script i.e., all of your use statements.

Veteran / Moderator

Jun 10, 2016, 8:00 AM

Post #5 of 10 (4725 views)
Re: [Trying] not in @INC [In reply to] Can't Post

User root installed the mod via cpan

I forgot to address this in my first post.

If cpan was setup and executed with its default settings, then modules will be installed under the @INC paths. However, the user can change the install location for the module by setting environment variables and/or passing build options.

If a module fails to install, it won't be found under the @INC paths but could/would still be found in the build directory.


Jun 10, 2016, 11:59 AM

Post #6 of 10 (4719 views)
Re: [FishMonger] not in @INC [In reply to] Can't Post

# Another way to trigger an email from the ISY
# We use UDP so the sender doesn't need to wait for us to finish.

use strict;
use warnings;

use Switch;
use Socket;
use Digest::MD5 qw(md5_hex md5_base64);
use DateTime;
use sigtrap qw/handler sig_handler normal-signals/;

my $PORT=15158; # We listen on this UDP port.
my $Mail=''; # Who gets the email
my $Log='/var/log/ISY2mail.log';
open(my $lf, '>>', $Log) or die "Could not open '$Log";


When I re-run 'cpan install DateTime' as root, the system says:
DateTime is up to date (1.28)
There are no failures but the module is still not in @INC.
Cpan was setup and executed with its default settings, because I don't know how to change them.
What do I do now?

Veteran / Moderator

Jun 10, 2016, 12:31 PM

Post #7 of 10 (4714 views)
Re: [Trying] not in @INC [In reply to] Can't Post

Did you do another search for to find where it was installed? Assuming the install was successful.

If the module is only found in the build directory under root's home dir, then that would indicate that the install process failed to complete. It also would indicate that the secondary issue is permission related since the root user would be the only one who would have access to that build directory.

At this point, I would do a force reinstall the module.


Jun 10, 2016, 3:59 PM

Post #8 of 10 (4708 views)
Re: [FishMonger] not in @INC [In reply to] Can't Post

I did the 'cpan -f -i DateTime' thing with the same result.
No in @INC.
To get user tom to run the program, I had to 'cpam install DateTime' as the user tom. After that, tom could run the program.
I can't believe that I have to go through the install as each of my 42 users. In fact I won't do that.

I did find a way to start the program at system start as user root.

Since a user's environment isn't set until they log in, I had to set root's environment before running the program at startup.
In root's crontab file I added the following line:

@reboot (. ~/.bashrc; /usr/local/bin/ &)

I guess perl is not the language for me to use unless I run everything as a user that can access all of the modules.

Thanks for the help, I'll try python or PHP.


Jun 10, 2016, 4:55 PM

Post #9 of 10 (4705 views)
Re: [Trying] not in @INC [In reply to] Can't Post

Hey, hey! Not so fast!
Just for the fun of it, though not expecting much, I queried the RPM database with 'dnf list perl-*'.

I got a dodo load of apps available, one of them is perl-DateTime.
So a simple 'dnf install perl-DateTime' installed the module in the proper location (@INC).
Now any user can run the program.

The cpan app will now be used only if dnf doesn't have it available.

OK, now back to learning perl.

Veteran / Moderator

Jun 10, 2016, 5:54 PM

Post #10 of 10 (4703 views)
Re: [Trying] not in @INC [In reply to] Can't Post

Glad to hear that you got the module installed correctly.

Besides using rpm, you can use yum (which is the standard fedora package manager) to install modules. The main problem with Fedora/CentOS (i.e. redhat) is that their packages are always out of date. Our company has over 1,000 (redhat) servers and over the past 5 yrs we've been migrating off of Fedora and moving to CentOS.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives