sh/awk script to scan .err files
Posted in 1992
Back in May, Brad Kuhn posted a handy perl script that scanned .err files for error messages. That is, it *looked* handy. Not having perl here, I couldn't tell first-hand. So, I implemented the idea in an sh/awk script. Enclosed is a shar of the script fglerr and its man page. I confess it has suffered from a little "creeping featurism," but not too much. I'd appreciate any comments you might have in a couple of areas: o We work mostly in compiled I4GL and ISQL here. Would this script work in other environments, and what changes would be required to make it handle RDS, ESQL/C, etc. o I chose "fglerr" as the best command name among the possible ones that came to mind. However, several files in $INFORMIXDIR start with "fgl". Does "fglerr" collide with any known or planned ISI or third-party names. o I'd like to hear about any bugs you find or ideas you have for improvement. I've also placed a copy of this shar in the ftp archive on mathcs.emory.edu in /pub/informix/pub/fglerr.shar. If anyone else has tools they'd like to add to the archive, send me a copy. Have fun, Walt. -- Walt Hultgren Internet: walt@rmy.emory.edu (IP 128.140.8.1) Emory University UUCP: {...,gatech,rutgers,uunet}!emory!rmy!walt 954 Gatewood Road, NE BITNET: walt@EMORY Atlanta, GA 30329 USA Voice: +1 404 727 0648 ------------------------------------------------------------------------------ #!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # fglerr fglerr.1 # # This shell archive created: Thu Jul 23 14:53:21 EDT 1992 # echo "Extracting file fglerr" sed -e 's/^X//' <<\\SHAR_EOF > fglerr X#!/bin/sh X# X# fglerr List Informix errors in *.err files X# X# X# SCCS ID: @(#) fglerr 1.2 7/23/92 14:51:34 X# X# X# Usage: fglerr [-fc] [-snum] [-enum] [-nv] [files] X# X# where: X# X# -fc use character "c" as the error line flag X# -snum list a maximum of <num> source lines before each error message X# -enum list a maximum of <num> lines from each error message X# -n list only source line numbers of errors X# -v list file names (may be done automatically based on arguments) X# X# X# This script scans error files generated by various Informix program, form X# and report compilers. It will list the source line number, error message X# and preceding source lines for each error. X# X# Code is provided near line 160 of the script that will set the default X# error flag based on the command name ("$0") used to invoke this script if X# the flag is not otherwise set. This allows you to link this file to names X# like "rpterr", "formerr", etc. That code is disabled in this release. X# X# A number of Informix-4GL utilities in $INFORMIXDIR have names beginning X# with "fgl". Although there is no known Informix file "fglerr" as of X# release 4.10.UC1, there may be such a file in a future release. Check X# subsequent Informix releases and/or $PATH to insure that this script does X# not interfere with DBMS operations. Or, install this script under a X# different name. X# X# X# Notice: Copyright 1992 by Yerkes Research Center of Emory University, X# Atlanta, Georgia, U.S.A. All Rights Reserved. X# X# X# Author: Walt Hultgren <walt@rmy.emory.edu> X# X# X X XCMD_NAME=`basename $0` X XUSAGE="usage: $CMD_NAME [-fc] [-snum] [-enum] [-nv] [files]" X X X# X# Set defaults X# X XMAX_SRC='5' # number of source lines to list before error message XMAX_ERR='100' # number of lines to list from each error message XNUM_ONLY='0' # default to not list only line numbers of errors X X X# X# Parse command line X# X Xset -- `getopt 'e:f:ns:v' $* 2>/dev/null` X Xif [ $? -ne 0 ] Xthen X echo "$USAGE" 1>&2 X exit 1 Xfi X XERR_FLAG='' XLIST_NAMES='' X Xfor ARG in $* Xdo X case "$ARG" in X -e ) MAX_ERR="$2" ; shift 2 ;; X -f ) ERR_FLAG="$2" ; shift 2 ;; X -n ) NUM_ONLY='1' ; MAX_ERR='0' ; MAX_SRC='0' ; BEG_SRC='0' ; shift ;; X -s ) MAX_SRC="$2" ; shift 2 ;; X -v ) LIST_NAMES='Y' ; shift ;; X -- ) shift ; break ;; X esac Xdone X X X# X# Set default verbose mode based on number of files specified X# X Xif [ "$#" -gt 1 ] Xthen X LIST_NAMES='Y' Xfi X X X# X# Generate list of error files from files on command line. Set error X# message line flag based on first file name if not already set. X# X XERR_FILES='' X Xfor FILE in $* Xdo X case "$FILE" in X X *.4g[el] | *.ace | *.arc | *.frm | *.per | *.sql | *.[ox] ) X X ERR_FILE=`echo $FILE | sed 's/...$/err/'` X X if [ -f "$ERR_FILE" ] X then X ERR_FILES="$ERR_FILES $ERR_FILE" X LIST_NAMES='Y' X else X echo "$CMD_NAME: no error file '$ERR_FILE' for '$FILE'" 1>&2 X exit 2 X fi X X if [ -z "$ERR_FLAG" ] X then X case "$FILE" in X *.4g[el] | *.[ox] ) ERR_FLAG='|' ;; X *.ace | *.arc | *.frm | *.per | *.sql ) ERR_FLAG='#' ;; X esac X fi X ;; X X - ) X ERR_FILES="$ERR_FILES -" X ;; X X * ) X if [ -f "$FILE" ] X then X ERR_FILES="$ERR_FILES $FILE" X else X echo "$CMD_NAME: no such file '$FILE'" 1>&2 X exit 2 X fi X ;; X esac X Xdone X X X# X# If no files specified, use standard input X# X Xif [ -z "$ERR_FILES" ] Xthen X ERR_FILES='-' Xfi X X X## X## Set error line flag based on command name if not already set X## X# X#if [ -z "$ERR_FLAG" ] X#then X# case "$CMD_NAME" in X# ace* | form* | frm* | per* | sql* ) ERR_FLAG='#' ;; X# * ) ERR_FLAG='|' ;; X# esac X#fi X X X# X# Scan error file(s) with awk to extract error messages X# X Xfor FILE in $ERR_FILES Xdo X # X # Print file name if required X # X X if [ -n "$LIST_NAMES" ] X then X echo X X if [ "$FILE" = "-" ] X then X echo "Error file: standard input" X FILE='' X else X echo