why bash script stops at gawk error

why bash script stops at gawk error

Post by Rita Bijlsm » Sat, 15 Dec 2001 23:22:31



  Hi,

   A bash script of mine that calls a gawk script and checks $? afterwards
   now just stops at a (particular?) fatal of gawk.

    - I run it as a cgi
    - When I replace the gawk call with   ! true    errorhandling occurs ok

   How could this happen?      

                         Thanks for any suggestions!,
                                                      Rita

   I can solve the gawk fatal, but
   just in case that the gawk fatal has something to do with the bash behavior
   I give the error message here:      

       gawk: buildtree.awk:1041: (FILENAME=opc.tree FNR=4457) fatal: Unmatch


    (apparently I again used a variable as a regexp, and it contains something
     wrong, but that is not the issue here)

--

  Oc -Technologies B.V. Venlo, The Netherlands      http://www.oce.com/

 
 
 

why bash script stops at gawk error

Post by Chris F.A. Johnso » Sun, 16 Dec 2001 01:16:04



>   Hi,

>    A bash script of mine that calls a gawk script and checks $? afterwards
>    now just stops at a (particular?) fatal of gawk.

>     - I run it as a cgi
>     - When I replace the gawk call with   ! true    errorhandling occurs ok

>    How could this happen?

>                          Thanks for any suggestions!,
>                                                       Rita

>    I can solve the gawk fatal, but
>    just in case that the gawk fatal has something to do with the bash behavior
>    I give the error message here:

>        gawk: buildtree.awk:1041: (FILENAME=opc.tree FNR=4457) fatal: Unmatch


>     (apparently I again used a variable as a regexp, and it contains something
>      wrong, but that is not the issue here)

Please post the code, or it will be impossible to diagnose.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

why bash script stops at gawk error

Post by Rita Bijlsm » Sun, 16 Dec 2001 02:09:37




> >   Hi,

> >    A bash script of mine that calls a gawk script and checks $? afterwards
> >    now just stops at a (particular?) fatal of gawk.

> >     - I run it as a cgi
> >     - When I replace the gawk call with   ! true    errorhandling occurs ok

> >    How could this happen?

> >                          Thanks for any suggestions!,
> >                                                       Rita

> >    I can solve the gawk fatal, but
> >    just in case that the gawk fatal has something to do with the bash behavior
> >    I give the error message here:

> >        gawk: buildtree.awk:1041: (FILENAME=opc.tree FNR=4457) fatal: Unmatch


> >     (apparently I again used a variable as a regexp, and it contains something
> >      wrong, but that is not the issue here)

> Please post the code, or it will be impossible to diagnose.

  Thank you for your interest. I put here the relevant part (I think) and
  below (i.e. attached) the full script, just in case (But are large posts considered bad?)

  `...' means something is left out
  I did not include the awk script, as the problem should be with the bash script.

 ...
case "$inputfile" in
   http*|www* )
    ...  
   *) filedate="`echo_pubfileinfo "$datafile"`"  ;
       gawk -f $awkbasefile -f $awkbuildfile stylesheet="$stylesheet" filedate="$filedate" pub=1 $stdinpars "$datafile"
   ;;
  esac
  if [ $? -ne 0 ]
  then
    echo "<HR>"        
  ...

Quote:> --
>     Chris F.A. Johnson                        http://cfaj.freeshell.org
>     ===================================================================
>     My code (if any) in this post is copyright 2001, Chris F.A. Johnson
>     and may be copied under the terms of the GNU General Public License

--

  Oc -Technologies B.V. Venlo, The Netherlands      http://www.oce.com/

[ buildtree 3K ]
#!/bin/bash
#
#    NAME
#       buildtree
#
#    SYNOPSIS
#       http://.../cgi-bin/buildtree?show%3dopc%2bmintitlevel%3d
#
# literal + : %2b
#         = : %3d
#
#   BUGS
#
#     One would expect that the commandline parameter method would be nice to use, it would not harm to
#     add $* in gawk's commandline.  But commandline parameters generated by html form contain
#     litereral `=' signs and as soon as one is in, bash sees no commandline parameters and this
#     is not a bash property, must come from cgi.  But then the cgi - html system is inconsistent?!
#
#    AUTHOR
#      Copyright (C) 2001 R.Bijlsma  GPL (public licence)
#

 pubdir=/nishome/bijr/pub
 stylesheet='http://pc1-bijr/~bijr/netbase.css'
 datafile='/nishome/bijr/pub/opc.tree'
 awkbasefile=/nishome/bijr/bin/baselib.awk
 awkbuildfile=/nishome/bijr/bin/buildtree.awk
 ascfile=/nishome/bijr/bin/ascii2html
 errorfile=/var/log/httpd/error_log

 stylefile="/nishome/bijr/www/${stylesheet##*/}"

  # ---------------------------------------------------------------
  # echo_pubfileinfo() :: echo public file info
  #                       file not found gives the filename, but
  #                       with empty () behind it.
  #
  #  Reasons:  
  #    - filename and () outside of ls, so that failures are clear.
  #
  echo_pubfileinfo() {
    echo "${1##*/}("`"ls" -l $1 | gawk '{ print $6 " " $7 " " $8 }' || echo "?? not found ??"`")  "

Quote:}

  echo Content-type: text/html
  echo

  echo_pubfileinfo $0

  echo "<br>"

  echo_pubfileinfo "$stylefile"
  echo_pubfileinfo "$datafile"
  echo_pubfileinfo "$awkbasefile"
  echo_pubfileinfo "$awkbuildfile"

  echo "<br>"

  stdinpars=" `gawk ' { gsub(/\\&/, " "); print}'`" # dont remove leading space

  echo "Pars from stdin: " $stdinpars

  inputfile=${stdinpars#*inputfile=}
  inputfile="${inputfile% *}"

  if [ "$inputfile" ]
  then
    datafile=$pubdir/$inputfile
    #e# add .tree if missing
  fi

  ---------------------------------------------------------------------------
 case "$inputfile" in
   http*|www* )
     lynxinputfile=`echo "$inputfile" | gawk -f $awkbasefile --source ' { print cgi2txt($0) }'` ;
     echo "$lynxinputfile"
     #e# have buildtree.awk give lynxinputfile instead of - (meaning stdin)
     lynx --dump "$lynxinputfile" | gawk -f $awkbasefile -f $awkbuildfile stylesheet="$stylesheet" filedate="$filedate" pub=1 $stdinpars
   ;;
   *) filedate="`echo_pubfileinfo "$datafile"`"  ;
       gawk -f $awkbasefile -f $awkbuildfile stylesheet="$stylesheet" filedate="$filedate" pub=1 $stdinpars "$datafile"
       #F# After this error this script did not continue:
       # gawk: buildtree.awk:1041: (FILENAME=opc.tree FNR=4457) fatal: Unmatch


   ;;
  esac
  if [ $? -ne 0 ]
  then
    echo "<HR>"
    echo "<H1>   Oeps:  FATAL from buildtree !!! </H1>"
    echo "<H2>here come the last 18 lines of httpd errorlog:</H2>"
    tail --lines=18 $errorfile | gawk -f $awkbasefile -f $ascfile --nohead
    if [ $? -ne 0 ]
    then
     echo "<H2>   Oeps:  also FATAL from ascii2html !!! </H2>"
     echo "<H3>here come the last 18 lines of httpd errorlog, dumped:</H3>"
       tail --lines=18 $errorfile
    fi
    echo "<HR>"
  fi
exit