Afficher un message
Vieux 15/03/2008, 03h35   #2
newbiegalore
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: cgi using shell script : unexpected behavior

On Mar 14, 5:26 pm, newbiegalore <banerjee.anir...@gmail.com> wrote:
> Hi everyone,
> I'm writing a small shell script to act like a cgi
> program. I have linked this script to a basic site I have developed
> via a form. I have attached the code below, and would greatly
> appreciate any pointers to correct glaring mistakes ..
>
> The problem: Everything displays as expected until I hit the second if
> statement. When I uncomment this statement all I get is a blank page,
> If I comment out this part ( if [ $flag1 -e 1 ]; then ) then I see
> what should be displayed until this point. The syntax for the if
> statement seems correct... I can't figure out what stupid mistake is
> causing this error
>
> To recap: When I comment out the part if [ $flag1 -e 1 ]; then, I can
> see Your URL iswww.hfdjhgjghjgh.comand then the flag1 value. As soon
> as I enable the if part I see a blank page! arrrrgh! please :-)
>
> #!/bin/sh
>
> wd=$PWD
>
> echo "Content-type: text/html"
> echo
>
> echo "<HTML><HEAD><TITLE>My first cgi</Title></HEAD>"
> echo " <BODY>"
> echo " <pre>"
>
> input=(`echo "$QUERY_STRING"`)
>
> #check for ; and |
> flag=(`echo $input | awk 'BEGIN{flag=0} /;|%3B/{flag=1} /\||%7C/
> {flag=2} END{print flag}'`)
>
> if [ $flag -e 0 ];
> then
> echo "Malformed URL: invalid characters used"
> echo "Please check URL"
> else
> burl=(`echo $input | awk '{split($0,a,"&");split(a[1],b,"=")rint
> b[2]}'`);
> echo "<H3>Your URL is </H3> $burl";
> #push this in psql db and check if we know
> #about it
> echo "SELECT sitename FROM urltable WHERE sitename = '$burl';" >
> $wd/query.sql
> flag1=(`psql -f $wd/query.sql urldb | awk 'BEGIN{a=0} /(0 rows)/
> {a=1} END{print a}'`)
> echo $flag1
>
> if [ $flag1 -e 1 ]; then
> #PROBLEM IS HERE
> else
> #do something
> fi
> #return the formatted page
> fi
> rm -f $wd/query.sql
> echo "</BODY>"
> echo "</HTML>"
> exit


OK things seem to be working!! don't really know why though .. I
removed all the text/blank spaces near the ifs and then re-wrote the
code there.. got my fingers crossed.

-A
  Réponse avec citation
 
Page generated in 0,05488 seconds with 9 queries