LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2009, 02:10 AM   #1
ravi_chobey
Member
 
Registered: Sep 2007
Location: Bangalore,India
Distribution: Fedora,Mandriva,Debian
Posts: 180

Rep: Reputation: 30
calling CGI script in CGI script


Hi All,

I am having a doubt, i have written a CGI script to enter the HOSTNAME of my PC in text box.What i want to do:as soon as i enter the hostname in that textbox and press apply,the other cgi script called should change the hostname in /etc/hostname file of my system.
Please guide me for that?

Regards,
Ravi
 
Old 03-18-2009, 10:48 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Best guidance: don't do it. If your webserver is properly set up, it should disallow this anyway. Writing to files outside the web root should normally be disallowed. Writing to any system file by any non-root user (and who would run a web server as root?) should be absolutely disallowed.
Having said all of that, your concept of a CGI within a CGI is probably incorrect. Reading between the lines, I'd say you have used a CGI to generate an HTML page containing a form. On that form is a text entry, and an action attribute that points the form to a CGI that handles the form. The form generator and the form handler can be the same script, or can be different scripts. If the handler is the same as the generator, it would generally use some information passed from the form to distinguish what action is appropriate to perform. The concept of one CGI embedding another does not apply here.
--- rod.
 
Old 03-19-2009, 04:07 AM   #3
ravi_chobey
Member
 
Registered: Sep 2007
Location: Bangalore,India
Distribution: Fedora,Mandriva,Debian
Posts: 180

Original Poster
Rep: Reputation: 30
Thumbs up

Thanks for your guidance. I have tried calling a CGI from HTML,but i am getting this error "File is executable but not a CGI".

When i have tried calling a CGI from CGI,it works fine.
I need your guidance for that.

Regards,
Ravi
 
Old 03-19-2009, 12:36 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
What do you mean by 'calling a CGI from HTML'? HTML is markup language. A CGI is invoked by the HTTP server when an HTTP client (browser) fetches a URL prefixed with 'cgi-bin/' (or whatever directory name it has been configured to use). Where did you see the error message that you posted?
It would be useful at this juncture for you to post some code fragments (please use [CODE] tags to preserve source code) that demonstrate the problem, and also your 'solution'; calling a CGI from a CGI.
I could only speculate that your 'executable but not a CGI' is not outputting a valid HTTP header. You have said nothing about your implementation language, but a sample solution in Perl would be to use the header() method of the CGI package.
Code:
#! /usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:all/;

    print header();
    print start_html( -title => "My Perl CGI" );

    #
    #  Your application goes here...
    #

    print end_html();
--- rod.
 
  


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
cgi script swift2008 Programming 3 08-18-2008 03:29 AM
cgi shell script jkeertir Linux - Newbie 2 04-09-2008 05:59 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:36 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