Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

here's a very simple script:

[root@poker cgi-bin]# cat globtest.pl
#!/usr/bin/perl -w

my $foo="/tmp/*";
my @glob=glob($foo);
my $size=scalar(@glob);


print "Content-type: text/html\n\n";
print "<html><head>\n";
print "SIZE: $size\n";
print"</head></html>\n";

when I run it from a URL on a RHEL5.3 system, it tells me how many files are in /tmp, but when I run it on a RHEL 6.2 box it reports 0.

what gives?

actually it's more complicated than I thought and forgot to mention. This is running in a VirtualBox VM. I have another machine running vmware and it works fine in a RHEL62 VM there.

-mark

share|improve this question
    
What version of Perl is running in each environment? And are you sure that there are files in /tmp on the RHEL 6.2 system? –  larsks Feb 14 '12 at 21:24
    
there are definitely files in /tmp. I've also extended my testing to try this on a fedora 16 system and am getting the same results. I even expanded the test to make it more interesting by looking at both /usr/* and a new directory /tmp2/*. It reports the correct number of files in all 3 when run from a shell, but reports 0 for both /tmp and /tmp2 when run from a webserver. I am running perl 5.14 on fedora. –  Mark J Seger Feb 15 '12 at 16:06
    
What happens if you run the script on the command line as the apache user? Something like: sudo -u apache /path/to/your/script –  larsks Feb 15 '12 at 16:38
    
good suggestion, but I did think of that and it worked correctly. sorry I forgot to mention it. keep those suggestions coming though... –  Mark J Seger Feb 15 '12 at 16:53

1 Answer 1

This is most likely related to SELinux. Or at least I found it to be the case, when I wrote a similar script.

The solutions for me to either disable SELinux , or change the SELinux ownership context, as documented by the following answer

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.