LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 04-08-2005, 12:04 AM   #1
rebel
LQ Newbie
 
Registered: Aug 2003
Distribution: CentOS
Posts: 24

Rep: Reputation: 15
Lightbulb FAQ: Internal Server Error / Premature End of Script Header / MS-DOS Carriage Return


This FAQ is for people who experienced Internal Server Error on running their Perl script. Hopefully it won't be as tormenting an experience to you as it was to me.

------------------------------------------------------------

One of the most common errors in executing a Perl script is due to the CR/LF problem (i.e. existence of MS-DOS carriage returns in the script).


What happens when there is a MS-DOS carriage return in your Perl script?

INTERNAL SERVER ERROR

The server encountered an internal error or misconfiguration and was unable to complete your request.



What does the error log says? (location in redhat linux: /etc/httpd/logs/error_log )

Premature end of script header



How do I check if I have MS-DOS carriage returns in my perl script?

Go to telnet command line and use vi editor to check.

vi -b filename.pl

^M means MS-DOS carriage return

(tip: type :q! to exit vi editor)



How do I fix it?

You can add -w to #!/usr/bin/perl (i.e. #!/usr/bin/perl -w). This seems to be a temporary solution only.

The permanent solution is to delete all MS-DOS carriage returns in the script.

Donboy's suggestion: "Easiest way (for me, anyway) is to use a text editing program that allows you to change it quickly. I'm using Edit Plus from www.editplus.com. This is a text editor that is like an "advanced" notepad. You can go into the "document" pulldown and look for CR/LF and change it to Unix. it will quickly change those returns into their unix equivalent."

Another way is to write and CHMOD 777 a simple perl script to delete the carriage return (make sure you write this script without MS-DOS carriage return!).

Code:
#!/usr/bin/perl

# Usage Notes
# This script erases MS-DOS carriage return that causes errors in perl scripts
#
# Go to telnet command line
# perl nocr.pl original.txt > modified.txt
# chmod 777 modified.txt

while(<>)
{
tr/\015//d; # delete octal 15 (carriage return)
print;
}

Last edited by rebel; 04-08-2005 at 12:06 AM.
 
Old 04-11-2005, 07:30 AM   #2
t3gah
Member
 
Registered: Dec 2004
Distribution: SuSE, RedHat, ubuntu, Debian
Posts: 734

Rep: Reputation: 30
Re: FAQ: Internal Server Error / Premature End of Script Header / MS-DOS Carriage Ret

Quote:
Originally posted by rebel
This FAQ is for people who experienced Internal Server Error on running their Perl script. Hopefully it won't be as tormenting an experience to you as it was to me.

------------------------------------------------------------

One of the most common errors in executing a Perl script is due to the CR/LF problem (i.e. existence of MS-DOS carriage returns in the script).


What happens when there is a MS-DOS carriage return in your Perl script?

INTERNAL SERVER ERROR

The server encountered an internal error or misconfiguration and was unable to complete your request.



What does the error log says? (location in redhat linux: /etc/httpd/logs/error_log )

Premature end of script header



How do I check if I have MS-DOS carriage returns in my perl script?

Go to telnet command line and use vi editor to check.

vi -b filename.pl

^M means MS-DOS carriage return

(tip: type :q! to exit vi editor)



How do I fix it?

You can add -w to #!/usr/bin/perl (i.e. #!/usr/bin/perl -w). This seems to be a temporary solution only.

The permanent solution is to delete all MS-DOS carriage returns in the script.

Donboy's suggestion: "Easiest way (for me, anyway) is to use a text editing program that allows you to change it quickly. I'm using Edit Plus from www.editplus.com. This is a text editor that is like an "advanced" notepad. You can go into the "document" pulldown and look for CR/LF and change it to Unix. it will quickly change those returns into their unix equivalent."

Another way is to write and CHMOD 777 a simple perl script to delete the carriage return (make sure you write this script without MS-DOS carriage return!).

Code:
#!/usr/bin/perl

# Usage Notes
# This script erases MS-DOS carriage return that causes errors in perl scripts
#
# Go to telnet command line
# perl nocr.pl original.txt > modified.txt
# chmod 777 modified.txt

while(<>)
{
tr/\015//d; # delete octal 15 (carriage return)
print;
}
Good info. Thanks for posting it for the people...

You should submit this as a Tutorial here > http://www.linuxquestions.org/questions/answers.php where it won't go away because it's not a "sticky".
 
Old 04-30-2005, 03:11 PM   #3
RickyRockRat
LQ Newbie
 
Registered: Apr 2005
Location: boise
Distribution: Red Hat - 6.2,7.3,9.0,FC3,FC4, FC5, Debian-3.1, Ubuntu 7x,8x,10x, DSL
Posts: 14

Rep: Reputation: 0
Use dos2unix/unix2dos
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
Premature end of script headers webhead Red Hat 5 09-22-2004 01:56 AM
Perl/CGI Problem "Premature Premature end of script headers: countdown.pl" newuser455 Linux - Software 2 07-18-2004 11:47 AM
Premature End of Script Headers (Error 500) bsdb3 Red Hat 5 05-06-2004 11:55 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 07:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration