2

For some reason I can't get a perl script to run in the cgi-bin folder. I haven't made these files and we've uploaded them to another server and they work fine.

However I've used the following test.pl file which works fine through bash (as root) and through the browser.

#!/usr/bin/perl
use strict;
use warnings;

#Useful for testing: Perl error messages, plus your die statements, will get
#sent to the browser.  Otherwise you will just see "Internal Server Error".
use CGI::Carp qw/fatalsToBrowser/;

#Always use the CGI module for your scripts.
use CGI;

#Create simple HTML output (taken directly from CGI documentation).
my $q = CGI->new;                    # create new CGI object
print $q->header,                    # create the HTTP header
      $q->start_html('hello world'), # start the HTML
      $q->h1('hello world'),         # level 1 header
      $q->end_html;                  # end the HTML

The other scripts that are running use the exact same permissions and settings. However, the scripts just bring up a 500 error message unless I change the top line from #!/usr/bin/perl to #!/usr/bin/perl -w (with warnings). The error log outputs the following error when i run it without the -w.

Error Log:

[Fri Sep 26 12:06:03 2014] [error] [client xxx.xxx.xx.xxx] (2)No such file or directory: exec of '/var/www/html/foldername/cgi-bin/ss000001.pl' failed
[Fri Sep 26 12:06:03 2014] [error] [client xxx.xxx.xx.xxx] Premature end of script headers: ss000001.pl

I should note that I can do nano /var/www/html/foldername/cgi-bin/ss000001.pl which opens the file and changing perl to -w does as explained above.

Does anyone know where I can start or see anything immediately wrong here?

Liam Sorsby
  • 129
  • 2
  • 5
  • I think you may have fallen into the trap of editing the script on windows which uses \r\n line endings, the \r is added to perl but the systm can't find `/usr/bin/perl\r` hence the no such file or directory error. Find and use dos2unix to convert the script to correct line endings. – wurtel Sep 26 '14 at 19:25
  • @wurtel the script itself is uploaded by a 3rd party software which works on a different server. Supprisingly, changing the head file of one of the scripts to /usr/bin/perl -w forces the script to work. How I do not know. – Liam Sorsby Sep 26 '14 at 19:27
  • Should be obvious, you're then adding a space after the /usr/bin/perl so that it can be found; an option -w\r is then passed, perl ignores the \r attached to the -w option. – wurtel Sep 26 '14 at 19:30
  • @wurtel Ah, without sounding stupid. If I upload to another server with just /usr/bin/perl it works no problem. – Liam Sorsby Sep 26 '14 at 19:34
  • Perhaps you use ftp once in binary mode and then in text mode? Text mode will fix those line endings (that's what it's for). Compare the filesizes. Alternatively try `cat -v ss000001.pl`, \r will show up as `^M` – wurtel Sep 26 '14 at 19:36
  • 1
    @wurtel your right, there's masses of ^M's all over the script. Must be incorrectly uploaded! Thank you – Liam Sorsby Sep 26 '14 at 19:41

0 Answers0