Other Added
#1 in Business Subscribe Email Print

You are here: Home > Internet and Businesses Online > Web Development > Running a CGI Script on a Web Server

Tags

  • going
  • permissions
  • cannot
  • called afterhtm
  • different nameversion
  • rename beforehtm

  • Links

  • Credit Score - An Introduction
  • Things to Check for Pest Control
  • Tips for Breezing Through Airport Security
  • Other Added - Running a CGI Script on a Web Server

    Is Customer Relationship Management Right for your Small to Mid-sized Business
    Customer Relationship Management has been a holy grail for Big Business for the past ten years. So what about Small to Mid-sized Business (SMB) applications? If you talk to CRM software vendors they will claim that CRM systems help SMBs become more efficient, drive more sales (your ROI) and increase the accuracy of your forecast.A few consultants have an alternative view: they see CRM as a process rather than a software product. A CRM process allows you to effectively manage your customer interactions (get to know your customers). This way you actually get to use the nice shiny tools that the CRM software vendors offer.While I tend to agree with t
    one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone

    Affiliate Revenue - Increasing Your Commissions
    What and what do you concentrate on if you want to increase your affiliate commissions? You'll have to do just two things to increase your commissions massively.Increase your traffic and increase your conversion rate.I'll buttress this point with this example...Let's say you send 1000 visitors to a merchant monthly and just 2% convert to buyers. If your commission per sale is $50, you'll get 20 x $50 = $1000.Now look at this...If you increase your traffic to 2000 and increase your conversion rate to 4%, you'll get 80 x $50 = $4000. That is, four times more just by doubling your traffic and doubling your conversion rate.Easy
    For many years I have been writing Perl scripts to process ASCII files of one sort or another on my computer. I typically do this when I need to reformat or tidy up a series of HTML pages, for example.

    To run a Perl script that is installed on your computer, which needs to process one or more files on your computer, and where the Perl interpreter is also installed on your computer, is very simple - you just need to double-click the perl script and it does the business - assuming that everything is set up correctly of course, for example, the location of the perl.exe program is defined in your path. You can also open a DOS window and type perl perlfile.pl to run a script (where perlfile.pl is the name of the Perl script you want to run).

    However, when it comes to running a Perl script, or CGI script, on a web server, things can be a bit trickier - not too tricky, but a bit trickier.

    In this article I'll look at two versions of the same script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server.

    The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name.

    Version 1 - the local version

    Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article.

    localScript.pl

    $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

    The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

    Version 2 - the web server version

    Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone

    Historical Economic Indicators in 2002
    If we look at trucking in August 2000 we see it was up even as diesel prices were rising, nice steady 3-4% quarterly gains, before the drop out. There were lots of mergers in trucking, which continued all through the 2001 and into this 2002 year. Rail was a roller coaster between 1998 and 1999 with 2000 showing great confidence in the mergers of the few years past. Air freight was up to. And there was plenty of water although the 2001 forecast back then was dismal and they were right bringing us to today’s efforts.Then came 9-11 in 2001 Air Freight, Shipping by rail and most major US Ports had dropped by 23% on average taking several months to recover.
    ame script: one that will run quite happily on a local machine (by double-clicking the script, for example), and one that will run on a web server.

    The script itself is very simple - it opens a file, changes some text inside the file, and then saves the file under a different name.

    Version 1 - the local version

    Here is version 1 of the script. This is the version that will run locally on a computer, without a web server is sight. Note that I've inserted spaces at appropriate places to prevent the code from being processed by your browser. I've done this wherever necessary in this article.

    localScript.pl

    $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

    The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

    Version 2 - the web server version

    Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone

    The Value Of Forums In Business Growth
    Recognition as an expert in your field leads to acceptance and respect which in turn leads to Sales! One of the fastest ways to become recognized as an expert is to offer helpful and valuable posts on a regular basis in forums where your target market or audience gather.To be honest, a membership in a forum offers more in the way of advertising value than all the eBooks, training programs, and membership training sites you could possibly join. Have you noticed that most of the publishers are in fact active forum members themselves?It has been said that to be successful, you have to hang out with those who are successful in whatever business you have
    s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    This script opens a file called before.htm, uses a regular expression to change the string 'hello world' to 'goodbye cruel world', and writes the contents to a file called after.htm. If after.htm does not exist, it is created.

    The file before.htm simply contains one line - hello world. So it's not even a proper HTML file in fact, but that doesn't matter for this exercise as it's the script that's important, not the file that's being processed.

    Version 2 - the web server version

    Here's the web server version of the script. It contains everything that's in version 1, plus a bit more. Again, I've inserted spaces where appropriate to ensure that the code displays correctly in your browser.

    webScript.cgi

    #!/usr/bin/perl -w
    use CGI qw(:all);
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone

    Advice When Calling Customer Service
    Anyone who has called tech support or customer service might agree that the experience can be very stressful. The following tips can make the experience more effective and help you get what you need.Before you call any support number make sure you have a pen and paper ready. Make notes on what exactly your issue is and how you want to ask it. You will also want to make a list of questions to ask the representative. Some common questions should include asking for their name and the hours of operation of the call center.If you are angry don’t bother calling. Being angry will not help you get what you want. It will only create resentment from the r
    w(fatalsToBrowser warningsToBrowser);
    warningsToBrowser(1);
    use strict;
    print header;
    my $name = "before.htm" or die "cannot assign to variable: $!";
    rename $name, "$name.bak" or die "cannot rename: $!";
    open (IN, "<$name.bak") or die "cannot open: $!";
    open (OUT, ">$name") or die "cannot create: $!";
    undef $/;
    my $line;
    while ($line = < IN >) {
    $line =~ s/hello world/goodbye cruel world/s;
    (print OUT $line);
    }
    close (OUT);
    close (IN);
    rename "before.htm", "after.htm";
    rename "before.htm.bak", "before.htm";

    A couple of initial points to note:

    1. Why does the script have a .cgi extension instead of a .pl extension? CGI is an abbreviation for Common Gateway Interface, which is a specification for transferring information between a web server and a CGI script. So CGI iteself is not a language, but CGI scripts can be written in a number of languages of which Perl is one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone

    Your Unique Point of View
    I had a chance to go to one of those big positive thinking rallies recently. I am one of those positive personal growth people that really enjoy that kind of thing. Throughout the day, I heard presentation after presentation from some of the best professional speakers in the business; General Tommy Franks, Mayor Rudy Guiliani, legendary Comedian Jerry Lewis and my hero, Zig Ziglar. They presented and spoke amazingly well. They were original.A couple of the other speakers (I will not name them) also did a fair job, but what I could not get past was that I had heard some of the jokes they told and some of the illustrations they used – THAT DAY! I paid $80 to s
    one. If you write a Perl script with a .pl extension, and then change that extension to .cgi, the script becomes a CGI script, and providing it conforms to the CGI specification, it will run on a web server.

    2. If you call this script webScript.pl it will run without any problems on a local disk - just as version 1 did. That's to say, all the extra code will not prevent it from running locally.

    Ok, lets go through the script line by line to see what's going on.

    Running the script

    To run the script you need to first upload the script and the file before.htm into the cgi-bin directory on your web server. On your web server the cgi-bin directory might be called something else, but it will probably be recognizable as the place where cgi scripts need to be located.

    By default, when you upload a file onto your web server it will probably have permissions of 644. You need to change these to 755 so that the script can be run by anyone. Your ISP should provide you with a way to do this. If not, contact me at john@dixondevelopment.co.uk and I'll send you a script to change the permissions for you.

    Once you have uploaded the files and changed the permissions, all you need to do is browse to the script in your favorite browser. If the browser window is blank, then everything has probably worked OK. Check in your cgi-bin directory to see if the file after.htm has been created and that it contains the words 'goodbye cruel world'.

    HTTP = HTML link (for blogs, profiles,phorums):
    <a href="http://www.otheradded.com/article/86350/otheradded-Running-a-CGI-Script-on-a-Web-Server.html">Running a CGI Script on a Web Server</a>

    BB link (for phorums):
    [url=http://www.otheradded.com/article/86350/otheradded-Running-a-CGI-Script-on-a-Web-Server.html]Running a CGI Script on a Web Server[/url]

    Related Articles:

    Corporate Business Gifts

    The Advantages Of Using Online Postage Stamps

    Mr. Rich vs. Mr. Job: How to Start a Dropship Business on eBay

    Bookmark it: del.icio.us digg.com reddit.com netvouz.com google.com yahoo.com technorati.com furl.net bloglines.com socialdust.com ma.gnolia.com newsvine.com slashdot.org simpy.com shadows.com blinklist.com