LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-14-2009, 03:48 AM   #1
pramod.srk
Member
 
Registered: Feb 2009
Posts: 47

Rep: Reputation: 15
Error - Premature end of script headers for C CGI Files


Dear All,
We are migrating an application from UNIX to RHEL-5.
I am getting following error:
"Premature end of script headers : : date.cgi

date.cgi is an executable with source written in C Lang.

Can anybody help me to resolve this error.

Thanks in Advance.


With Regards
Pramod
 
Old 05-14-2009, 05:25 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,607

Rep: Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532
I guess you get the error from a webserver. You can check the webserver's error log for hints and also try to run the cgi from CLI and see if it produces valid HTML.
Most likely you'll need the sources to recompile it for linux.

Regards
 
Old 05-14-2009, 05:44 AM   #3
pramod.srk
Member
 
Registered: Feb 2009
Posts: 47

Original Poster
Rep: Reputation: 15
Thanks for the reply..

I got this error in the error log file of apache server.

I recompiled the file in RHEL-5.

The date.cgi accepts the date and time format as parameters through http and then creates an image of date using fly (which already installed).

The tool to test date.cgi using html is as follows

<html><body background="NA02.GIF">
date test<br>
<img src=today "date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg">
</body></html>


The GIF file is present in the same directory where date.cgi resides.
 
Old 05-14-2009, 06:00 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,607

Rep: Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532
What happens if you run the script directly in CLI:
Code:
/path/to/apache-cgi-bin/date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg
Could be a permissions problem, if the cgi cannot create the image in the specified directory.
 
Old 05-14-2009, 06:18 AM   #5
pramod.srk
Member
 
Registered: Feb 2009
Posts: 47

Original Poster
Rep: Reputation: 15
I have given the permission 755 and tried even 777 as well to the directory and file.
But giving the same problem.
 
Old 05-14-2009, 06:37 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,607

Rep: Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532
755 is generally OK, but in your case since you use RHEL it might be a SELinux problem, preventing the cgi to run correctly. That's why I'm telling you to run it from command line and see what it outputs. Better yet, run it as the user running apache.
 
Old 05-14-2009, 07:36 AM   #7
pramod.srk
Member
 
Registered: Feb 2009
Posts: 47

Original Poster
Rep: Reputation: 15
I ran date.cgi as follows with apache user
$./date.cgi "mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg"

and I got nothing.

Do you have any idea about how to debug.
I tried by running gdb , but got null value for "getenv("REQUEST_METHOD")" and program exited.
 
Old 05-14-2009, 07:47 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,607

Rep: Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532
You should run it exactly as it is requested by the browser:
Code:
./date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg
Btw on what Unix was this cgi first running?
 
Old 05-14-2009, 08:07 AM   #9
pramod.srk
Member
 
Registered: Feb 2009
Posts: 47

Original Poster
Rep: Reputation: 15
It gives the the error as follows
[root@odn235 src]# ./date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg&
[8] 2506
[9] 2507
[10] 2508
[11] 2509
[12] 2510
[13] 2511
-bash: ./date.cgi?mode=date: No such file or directory

The CGI's were running on HP - UNIX 32 bit machine.

The current machine is also RHEL-32 bit machine.
 
Old 05-14-2009, 08:38 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,607

Rep: Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532Reputation: 1532
It should be better run it as the apache user. Most likely it cannot find the directory to write the image or something like that. Are you sure it's not a SELinux problem?
Could you post the code here, so someone familiar with C more than me could help?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Premature end of script headers: CGI fatturi Linux - Newbie 4 07-19-2007 05:55 PM
apache and cgi problem. Premature end of script headers. JAdj Linux - Software 1 10-25-2006 04:45 AM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 12:43 PM
Perl/CGI Problem "Premature Premature end of script headers: countdown.pl" newuser455 Linux - Software 2 07-18-2004 12:47 PM
Premature End of Script Headers (Error 500) bsdb3 Red Hat 5 05-06-2004 12:55 PM


All times are GMT -5. The time now is 04:08 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration