3

I've written a shell script that does stuff on Centos64

At the end of this script, I run a perl script.

It works fine as root (I have installed the perl modules), but when I run it as a system user

I get the message:

./UserActivityReport.sh Can't locate MIME/Lite.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /optreports/sendmailUAR.pl line 3. BEGIN failed--compilation aborted at /opt/reports/sendmailUAR.pl line 3.

As if the modules were not installed for the user...

I run the script with this command in my shell script:

/usr/bin/perl  /opt/reports/sendmailUAR.pl

Why is it not running?

NOTE: I cannot install the perl modules with the system user.

=== There you go:

perl -MMIME::Lite -MData::Dumper -e'print Dumper \%INC'
$VAR1 = {
          're.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/re.pm',
          'warnings/register.pm' => '/usr/lib/perl5/5.8.8/warnings/register.pm',
          'XSLoader.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/XSLoader.pm',
          'IO/Handle.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/IO/Handle.pm',
          'MIME/Types.pm' => '/usr/lib/perl5/site_perl/5.8.8/MIME/Types.pm',
          'SelectSaver.pm' => '/usr/lib/perl5/5.8.8/SelectSaver.pm',
          'IO/Seekable.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/IO/Seekable.pm',
          'warnings.pm' => '/usr/lib/perl5/5.8.8/warnings.pm',
          'File/Basename.pm' => '/usr/lib/perl5/5.8.8/File/Basename.pm',
          'Fcntl.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Fcntl.pm',
          'IO.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/IO.pm',
          'Symbol.pm' => '/usr/lib/perl5/5.8.8/Symbol.pm',
          'bytes.pm' => '/usr/lib/perl5/5.8.8/bytes.pm',
          'MIME/Type.pm' => '/usr/lib/perl5/site_perl/5.8.8/MIME/Type.pm',
          'Carp.pm' => '/usr/lib/perl5/5.8.8/Carp.pm',
          'MIME/Base64.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/MIME/Base64.pm',
          'Exporter/Heavy.pm' => '/usr/lib/perl5/5.8.8/Exporter/Heavy.pm',
          'File/Spec/Unix.pm' => '/usr/lib/perl5/5.8.8/File/Spec/Unix.pm',
          'FileHandle.pm' => '/usr/lib/perl5/5.8.8/FileHandle.pm',
          'strict.pm' => '/usr/lib/perl5/5.8.8/strict.pm',
          'Exporter.pm' => '/usr/lib/perl5/5.8.8/Exporter.pm',
          'vars.pm' => '/usr/lib/perl5/5.8.8/vars.pm',
          'MIME/Lite.pm' => '/usr/lib/perl5/site_perl/5.8.8/MIME/Lite.pm',
          'MIME/QuotedPrint.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/MIME/QuotedPrint.pm',
          'File/Spec.pm' => '/usr/lib/perl5/5.8.8/File/Spec.pm',
          'overload.pm' => '/usr/lib/perl5/5.8.8/overload.pm',
          'IO/File.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/IO/File.pm',
          'Mail/Address.pm' => '/usr/lib/perl5/site_perl/5.8.8/Mail/Address.pm',
          'Data/Dumper.pm' => '/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Data/Dumper.pm'

};

Rgonomike
  • 338
  • 6
  • 18
  • run as root `perl -MMIME::Lite -MData::Dumper -e'print Dumper \%INC'` and post here the output. – salva Sep 15 '11 at 11:16
  • The system user's @INC doesn't seem to have `/usr/lib/perl5/site_perl/5.8.8/` in it. Take a look at: http://stackoverflow.com/questions/2526804/how-is-perls-inc-constructed-aka-what-are-all-the-ways-of-affecting-where-per – Jon Lin Sep 15 '11 at 11:36
  • The file is there alright ... What are its permissions? – tripleee Sep 15 '11 at 11:40
  • @Lin how so? It's included in \@INC according to the error message. – tripleee Sep 15 '11 at 11:41
  • [root~]# ls -l /usr/lib/perl5/site_perl/5.8.8/ total 60 drwxr-x--- 3 root root 4096 Sep 14 13:09 Date drwxr-x--- 3 root root 4096 Sep 14 13:09 Email drwxr-x--- 4 root root 4096 Sep 14 13:10 Mail drwxr-x--- 2 root root 4096 Sep 14 13:10 MIME drwxr-x--- 2 root root 4096 Sep 15 06:30 OLE drwxr-x--- 2 root root 4096 Sep 15 06:30 Parse drwxr-x--- 2 root root 4096 Sep 14 13:10 Pod drwxr-x--- 3 root root 4096 Sep 15 06:30 Spreadsheet drwxr-x--- 2 root root 4096 Sep 14 13:09 Time -r--r--r-- 1 root root 6500 Aug 21 07:19 version.pm -r--r--r-- 1 root root 9887 Aug 21 07:12 version.pod – Rgonomike Sep 15 '11 at 11:44
  • My bad, it's in the error message. Was the MIME/Lite.pm module installed by CPAN? Are the permissions for that file readable by all? – Jon Lin Sep 15 '11 at 11:46
  • @Rgonomike as root, try `chmod a+r -R /usr/lib/perl5/site_perl/5.8.8/MIME` – Jon Lin Sep 15 '11 at 11:48
  • Yes, it's been install with CPAN: [cipadmin@]$ locate Lite.pm /home/cipadmin/.cpan/build/MIME-Lite-3.027/blib/lib/MIME/Lite.pm /home/cipadmin/.cpan/build/MIME-Lite-3.027/lib/MIME/Lite.pm – Rgonomike Sep 15 '11 at 11:49
  • Isn't it possible that inside my shell sript i need to run the perl script with some Options? – Rgonomike Sep 15 '11 at 11:58

3 Answers3

2

In one of the comments, you have posted a directory listing like this:

[root~]# ls -l /usr/lib/perl5/site_perl/5.8.8/
total 60
drwxr-x--- 3 root root 4096 Sep 14 13:09 Date
drwxr-x--- 3 root root 4096 Sep 14 13:09 Email
drwxr-x--- 4 root root 4096 Sep 14 13:10 Mail
drwxr-x--- 2 root root 4096 Sep 14 13:10 MIME
drwxr-x--- 2 root root 4096 Sep 15 06:30 OLE
drwxr-x--- 2 root root 4096 Sep 15 06:30 Parse
drwxr-x--- 2 root root 4096 Sep 14 13:10 Pod
drwxr-x--- 3 root root 4096 Sep 15 06:30 Spreadsheet
drwxr-x--- 2 root root 4096 Sep 14 13:09 Time
-r--r--r-- 1 root root 6500 Aug 21 07:19 version.pm
-r--r--r-- 1 root root 9887 Aug 21 07:12 version.pod

It should be fairly evident that users other than root do not have access to these files. You should probably do more thorough audit by looping over all of @INC and changing permissions as necessary, but for a start, find /usr/lib/perl5/site_perl/5.8.8 -type d -exec chmod a+rx {} \;

tripleee
  • 175,061
  • 34
  • 275
  • 318
1

I'm betting root's umask is such that files are not world readable by default.

find /usr/lib/perl5 -not -perm -o=r 

Anything files listed are not world readable (and probably should be). You can fix it this way

find /usr/lib/perl5 -not -perm -o=r -exec chmod o+r {} +

If you wish to make all files matched with the first command readable by everyone.

sorpigal
  • 25,504
  • 8
  • 57
  • 75
1

MIME::Lite is at /usr/lib/perl5/site_perl/5.8.8/MIME/Lite.pm and /usr/lib/perl5/site_perl/5.8.8 is in system's @INC path.

As user system check that you can read that file:

cat /usr/lib/perl5/site_perl/5.8.8/MIME/Lite.pm

If you get an error doing so check the permissions of the file and the parent directories.

Otherwise, run the script as system with strace and see why it is failing to find the module file.

salva
  • 9,943
  • 4
  • 29
  • 57