Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Then, print something that you know will get to the HTML page.
Code:
print "testing 1,2,3...";
Print the result of the `ls` command to standard error, and find it in the server error logs:
Code:
print STDERR `ls`;
After you've done all of that, you will probably find that ls is not being found in the web server's path, and you need to explicitly give the fully qualified path to the executable.
--- rod.
Did the ouptut from 'ls' show up in the web server's error log file? If not, then how do you know that 'ls' was actually invoked? Did you try using a fully qualified pathname for the 'ls' command? What happened there? You can verify this with something like this:
Code:
my $lsOut = `ls`;
print "ls Output:\n", $lsOut;
If you only see the literal text heading 'ls Output:' on your browser, it tells me that ls is not actually being invoked, because the server didn't have it in it's $PATH variable. Try changing 'ls' to '/bin/ls' or wherever ls is installed on your system.
Better still, since you are using perl, try using the opendir()/readdir() functions.
--- rod.
What part did you try? If you only tried the part in the [code] block, then you've merely confirmed what I've been trying to tell you since my first post. What have you done to prove that 'ls' is actually being invoked?
Get your CGI script to print the value of the PATH environment variable:
Code:
print "PATH: ", $ENV{'PATH'},"\n";
If the 'ls' executable is not in the list of places in $PATH, then you need to use the fully qualified directory & filename of the ls executable in your script in order to invoke it. Have you done this?
Please answer all of these questions. In order to help you, you need to supply information.
What's to solve? You haven't said what doesn't work.
Look, I like to help people solve their problems. I ask thoughtfully composed questions to try to get the information necessary to first diagnose the problem, and then to provide a solution, if one exists. Please do yourself a favor and others the courtesy of replying with at least an attempt at answering the questions that are posed.
--- rod.
Okay, now we're getting somewhere. When you ran the code above, it was run as a CGI called by a web server, right? This is important, because the web server has its own user ID and attendant permissions. Running it standalone as a normal user or as root is not a valid test. If this is true, then we can be fairly sure that the ls command is actually being invoked, unless your server has restricted execution of these binaries by SElinux. I'm not sure how to selectively remove restrictions in Selinux; I normally run with is disabled. You may want to check that.
Your touch command should fail in a properly set up system, because you don't want your web server to have write permissions in the cgi-bin directory. You may be able to create files in other directories, if you give the directories appropriate permissions and ownerships. '/tmp' is often a good candidate, as it typically has world-read & world-write permissions. If you cannot write there, suspect Selinux.
If you really just want to acquire directory listings, and ls is not being used merely as a trivial test, then I suggest you look at the perl functions opendir() and readdir(). These can do everything that ls can do.
Code:
#! /usr/bin/perl -w
use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
print header, start_html('First Task');
opendir( DIR, "." );
my @filesAndDirs = readdir(DIR);
foreach my $fileOrDir ( sort @filesAndDirs ){
print $fileOrDir."<BR>\n";
}
print end_html;
If this works, then, I suspect Selinux is in your way.
--- rod.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.