Results 1 to 6 of 6

Thread: How to create CGI script in bash?

  1. #1
    Join Date
    Apr 2010
    Posts
    80

    How to create CGI script in bash?

    Hello members, I have created an uncomplicated web hosting registration bash script that creates a innovative user in my web hosting system. Now the predicament is that I want to mechanize it, that user can register themselves from html web form transferring their request to this bash script in cgi-bin directory (or maybe modify this bash script as cgi etc..). So I thought that you guys can explain me how to create CGI script in bash? Please provide some helpful solution fast.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: How to create CGI script in bash?

    You have to give execute permission, and then be called from the browser :
    http://localhost/cgi-bin/gcgil
    file: / usr / lib / cgi-bin / gcgil
    The following code would be useful for you :
    Code:
    #! / Bin / bash 
    
    # Set the following variable to the name you want. 
    # It will be the script directory. 
    SCRIPTDIR = "script.cgi" 
    SCRIPTBASE = "ligcg.cf" 
    EXT = ". Cf" 
    
    # Far from be directed to an administrator ... 
    # 
    if [[$ (EUID) == 0]]; Then 
    echo "You should not use the Administrator!" echo 
    exit 
    fi 
    
    # Functions 
    #################### 
    
    # UserStdOut 
    # 
    # No parameters. To differentiate between two users, 
    # The shell and the webserver 
    # 
    # End if a wrong call from the browser. 
    
    (userStdOut function 
    if ["$ NOCGI GATEWAY_INTERFACE" = "NOCGI"]; Then 
    # Normal output of characters per console 
    SCRIPTUID = 2 
    else 
    if ["/ $ SCRIPTDIR"! = "$ PATH_INFO"] & & \ 
    [! -F "$ (SCRIPTDIR) / $ (SCRIPTBASE)"]; Then 
    set-f 
    echo 'Content-type: text / plain; charset = "UTF-8"'; echo 
    if ["$ PATH_INFO NOWD" = "NOWD"]; Then 
    echo "Corrects URL: http:// $ SERVER_NAME $ SCRIPT_NAME / $ SCRIPTDIR" 
    else 
    echo "This ... SCRIPTDIR only $ () / $ (SCRIPTBASE) has" \ 
    "Authority to perform this action:))" 
    fi 
    exit 
    else 
    SCRIPTUID = 1 
    fi 
    fi 
    ) 
    
    
    # If the file cgibin / bincgi not exist, create the function which will replace 
    # Temporarily that there Epera find. 
    # 
    
    if [-f $ SCRIPTDIR / $ SCRIPTBASE] Then 
    SCRIPTDIR $ source / $ SCRIPTBASE 
    else 
    (start function 
    in case $ SCRIPTUID 
    1) echo 'Content-type: text / plain; charset = "UTF-8"'; echo 
    cat <<_eOt_ 
    Script Initializing ... 
    
    _eOt_ 
    ;; # This is the web server by. Need a notice that we do.; 
    2) clear 
    NOP = $ '\ X1B [0; 0m' 
    ROJ = $ '\ X1B [31; 01m' 
    BLA = $ '\ X1B [0; 01m' 
    VER = $ '\ X1B [32, 01m' 
    cat <<_eOt_ 
    JRO $ (hello) $ (USER) $ (NOP) 
    
    're running this script ($ (VER) $ (basename $ 0) $ (NOP)) from a console 
    $ (BLA) $ (TERM) $ (VER) $ (tty) $ (NOP) 
    but is designed to run as \ 
    CGI $ (VER) $ (NOP) and show it through web browser. 
    
    You put it in the directory of your cgi $ (BLA) $ (NOP)'s usually 
    $ (VER) / usr / lib / cgi-bin 
    / Var / www / cgi-bin 
    NOP ...${) 
    and call it from the browser, for example 
    Http://localhost/cgi-bin/ $ (VER) $ (basename $ 0) 
    http:// $ (uname-n) / cgi-bin / $ (basename $ 0) $ (NOP) 
    
    See you in the browser ... 
    _eOt_ 
    echo 
    exit 
    ;; # Final output to the console:)) 
    esac 
    
    if [-d $ SCRIPTDIR] Then 
    echo "Directory $ SCRIPTDIR echo there :))"; 
    if [! -W $ SCRIPTDIR] Then 
    echo "but you must have write permission to $ (whoami)"; echo 
    echo "~ $ sudo chown $ (whoami): $ (GID) $ (dirname $ 0) / $ (SCRIPTDIR) 
    echo "although you can continue" 
    fi 
    else 
    echo "You need to create the directory $ (dirname $ 0) / $ (SCRIPTDIR)" echo 
    echo "for this from a console running" 
    echo "~ $ sudo mkdir $ (dirname $ 0) / $ (SCRIPTDIR) 
    echo "~ $ sudo chown $ (whoami): $ (GID) $ (dirname $ 0) / $ (SCRIPTDIR) 
    fi 
    
    echo, echo "finally located the file: \" $ SCRIPTDIR / $ SCRIPTBASE \ "" 
    echo "to complete the installation" echo 
    
    echo "$ (basename $ 0) to $ (whoami): Bye" 
    ) 
    fi 
    
    userStdOut 
    start 
    
    exit

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to create CGI script in bash?

    I think that you should also know about the Modules. The development of modules is very simple, follow rules, they must have the extension .Cf and contain a main function and two descriptions. The functions start with the file name without extension, for example create a test module called test.cf this must contain the main function :
    test_init
    and two more that are informative
    test_name
    test_description
    The following functions begin and end the formatted output to the browser :
    Code:
    PersonalDoc "title page" 
    initZone 'beginning of a drop zone' 
    ... 
    Endzone 
    FinalizaDoc

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to create CGI script in bash?

    The following code shows, can serve as a template:
    file: / usr / lib / cgi-bin / script.cgi / test.cf
    Code:
    (test_init function 
    IniciaDoc 'Module testing' 
    initZone 'Testing ...' 
    
    echo "This ... testing .. one two, one two ..." 
    
    Endzone 
    FinalizaDoc 
    ) 
    
    (test_name function 
    echo "Test Module" 
    ) 
    
    (test_description function 
    echo "test file or template" 
    )

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to create CGI script in bash?

    The function variable leeVariable return the value of the variable that is sent through a form with POST method. Below you will find the module shell is also very simple one to understand.
    Code:
    (arxius_init function 
    IniciaDoc 'Module Arxius' 
    initZone 'File Browser (alpha)' 
    if [$ CGI_GETPOST] Then 
    ="$(( ACT_DIR leeVariable act_dir) | sed-e 's: / [A-Za-z0-9 _,.-]*/ \. \.:: G') " 
    fi 
    
    tmpStr = "$ (echo $ (SCRIPT_NAME) | sed-e" s :^/.*/:/:")" 
    DIRBE = "$ (echo $ (SCRIPT_FILENAME) | sed-e" s: $ tmpStr ::")" 
    tmpStr unset 
    
    if ["$ NOP (echo" $ ACT_DIR "| grep $ DIRBE)" == "NOP"] Then 
    ACT_DIR = "$ DIRBE" 
    fi 
    
    echo "<span style=\"color: yellow; font-size: large;\">" \ 
    "$ (Echo $ (ACT_DIR = $ DIRBE) | sed-e" s: $ DIRBE: / '| sed-e "s ://:/:")" \ 
    "</ Span> <br>" 
    
    cd "$ (ACT_DIR) 
    
    cat <<_eOt_ 
    language="JavaScript" <script type="text/javascript"> <! - 
    CambiaDir function (otroDir) ( 
    document.formArxius.act_dir.value = document.formArxius.act_dir.value + \ 
    "/" + OtroDir; 
    document.formArxius.submit (); 
    ) 
    --></ Script> 
    name="formArxius" <form method="post"> 
    <input type="hidden" name="act_dir" value="${ACT_DIR}"> 
    </ Form> 
    _eOt_ 
    
    (Ls-a | grep-v ~ $) | while read file; do 
    if [-d "$ file"]; Then 
    if ["$ file"! = "." ]; Then 
    if ["$ file"! = ".." -O "$ ACT_DIR"! = "$ DIRBE"]; Then 
    echo "<a href=\"javascript:CambiaDir('${archivo}')\"> <span" \ 
    "Style = \" color: blue; font-weight: bold; \ "> $ file" \ 
    "</ Span> </ a> <br>" 
    fi 
    fi 
    elif [-f "$ file"-o-x "$ file"]; Then 
    if ["$ (file $ file | grep text) NOP" \ = "NOP"] Then 
    if [-w "$ file"]; Then 
    echo "<span style=\"color: white;\"> $ file </ span> <span \ 
    "Style = \" font-size: x-small; font-style: italic; \ ">" \ 
    [Edit] </ span> <br> " 
    else 
    echo "<span style=\"color: white;\"> $ file </ span> <span \ 
    "Style = \" font-size: x-small; font-style: italic; \ ">" \ 
    "[Show] </ span> <br>" 
    fi 
    else 
    echo "$ file <span style = \" font-size: x-small; font-style: "\ 
    "Italic, color: yellow \"> bin </ span> <br> " 
    fi 
    fi 
    done 
    
    Endzone 
    FinalizaDoc 
    ) 
    
    (archives_name function 
    echo "File Browser" 
    ) 
    (archives_description function 
    echo "Browse the directory tree and files on the server" 
    )

  6. #6
    Join Date
    Sep 2010
    Posts
    5

    Re: How to create CGI script in bash?

    CGI uses two methods to pass data between the browser and the web server, GET and POST. The GET method passes data in the URL and is the method employed here. The web server will pass environment variables into the execution environment of the CGI shell script which also may be used.

Similar Threads

  1. Bash script needs to e-mail output
    By Kim|ball in forum Technology & Internet
    Replies: 4
    Last Post: 27-05-2011, 10:19 AM
  2. Linux bash script with the command w
    By Trini Alvarado in forum Operating Systems
    Replies: 4
    Last Post: 22-03-2010, 12:11 PM
  3. Create bash script for ftp
    By teenQ in forum Operating Systems
    Replies: 4
    Last Post: 04-03-2010, 07:37 PM
  4. Bash script if then else help
    By Unix'EM in forum Software Development
    Replies: 3
    Last Post: 18-08-2009, 06:34 PM
  5. Create a bash script for sftp
    By Xubuntu_user in forum Operating Systems
    Replies: 3
    Last Post: 06-08-2009, 09:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,505,234.18469 seconds with 17 queries