Find the answer to your Linux question:
Results 1 to 3 of 3
Hi I am new to cgi and shell programming i have a cgi script that is accessed via browser http://www.example.org/cgi-bin/myscr...c4167d83697a6f before the script is executed i would like to do ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    2

    Question Need help to write a simple cgi shell script


    Hi
    I am new to cgi and shell programming

    i have a cgi script that is accessed via browser

    http://www.example.org/cgi-bin/myscr...c4167d83697a6f

    before the script is executed i would like to do some checks

    in php i would do this.

    PHP Code:
    $secure_code 'somerandomstringtosecure';
    if ( 
    md5 ($_GET['random'] . $secure_code) !== $_GET['hash'] ) {
        die(
    "access denied");

    how can i write this in shell script? This is not a perl script. it starts with

    #!/bin/sh



    Thanks
    Shuja

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    I do not believe that you can write CGI scripts using Bash. However, a quick Google search reveals:
    http://bashlib.sourceforge.net/

    Try taking a look at that.

  3. #3
    Just Joined!
    Join Date
    Mar 2007
    Posts
    2
    After a lot of searching and learing i came up with following, might help anyone else

    #!/bin/sh

    echo "Content-type: text/html"
    echo
    echo "<pre>Syncing web ... "
    echo
    ST1=`echo $QUERY_STRING | cut '-d&' -f1`
    ST2=`echo $QUERY_STRING | cut '-d&' -f2`
    key=`echo $ST1 | cut -d= -f2`
    hash=`echo $ST2 | cut -d= -f2`
    secret="47e0a03523feddc35"
    hash2=`md5sum --string="$key$secret" | cut -f1 -d ' '`
    echo "$key"
    if [ "x$key" == "x" ] ; then
    echo "Key not given"
    exit 1
    fi

    if [ "x$hash" == "x" ] ; then
    echo "Hash not given"
    exit 1
    fi
    if [ $hash != $hash2 ] ; then
    echo "Test Failed"
    exit 1
    fi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •