Hello,
I am working on my first ksh script to review daily reports. The script uses different functions to check different types of reports in csv format. A control file gets read in with information regarding the report, other info, and the function to use.
When I run the script I get the error "syntax error at line 239 : `else' unexpected". Line 239 correlates to the 2nd red line. I had a similar problem on search function 2 before commenting it out. It read "syntax error at line 205 : `done' unexpected". Line 209 correlates to the 1st read line. Not sure why it is always the line after but that is the correct line.
Any help is appreciated!
# Seach Function for 'Multi Line - Single Field'
#search2 ()
#{
# #Remove the report header from the file. Commented out to continue troubleshooting.
# TOTALLINES=wc -1 ${RPTFILE}
# REPORTNOHEAD=$(echo ${RPTFILE} | tail -$(${TOTALLINES}-${STARTLINE}))
#
# for ERROR in $(more ${REPORTNOHEAD} | cut -f${STARTFIELD} -d ",")
# do
# if [[ ${ERROR} = ${STRING1} && ${ERROR} != ${STRINGEXCLUSION} ]];
# then
# echo "${RPTFILE} has been identified as having an error. ${INSTRUCTIONS}" >> ${ERROREMAIL}
# else
# echo "${RPTFILE} has no detected errors. >> ${APPLOG}
# fi
# done
#}
# Seach Function for 'Reports that return no data, w/o "No Data Selected."'
search3 ()
{
echo "\n Search Function 3 used by ${REPORT} "
REPORTLINECOUNT=$(wc -l ${RPTFILE})
if [[ ${REPORTLINECOUNT} -ge ${STARTLINE} ]];
then
echo "${RPTFILE} has been identified as having an error. ${INSTRUCTIONS}" >> ${ERROREMAIL}
else
echo "${RPTFILE} has no detected errors. >> ${APPLOG}
fi
}
# Seach Function for 'Blank Report w/ "No Data Selected."'
search4 ()
{
echo "\n Search Function 4 used by ${REPORT} "
RPTLINE=$(more ${RPTFILE} | head -${STARTLINE} | tail -1)
RPTFIELD=$(echo ${RPTFILE} | cut -f${STARTFIELD} -d ",")
if [[ ${RPTFIELD} = ${STRING1} ]];
then
echo "${RPTFILE} has no detected errors. >> ${APPLOG}
else
echo "${RPTFILE} has been identified as having an error. ${INSTRUCTIONS}" >> ${ERROREMAIL}
echo "Error Found" >> ${APPLOG}
fi
}
#Reset Variables
LINENUMBER=0
ERRFOUND=0
#Loop through Control File
for EMAIL in $(more ${CONTROLFILE} | cut -f 2 -d ":")
do
#Grab individual Control File Line
LINENUMBER=$((${LINENUMBER} + 1))
LINE=$(more ${CONTROLFILE} | head -${LINENUMBER} | tail -1)
#set search variables
LOCATION=$(echo ${LINE} | cut -f 4 -d ":")
STARTLINE=$(echo ${LOCATION} | cut -f 1 -d "*")
STARTFIELD=$(echo ${LOCATION} | cut -f 2 -d "*")
#Variables
STRING1=$(echo ${LINE} | cut -f 3 -d ":" | cut -f 1 -d " ")
CONTROLLINENUMBER=$(echo ${LINE} | cut -f 1 -d ":")
REPORT=$(echo ${LINE} | cut -f 5 -d ":")
INSTRUCTIONS=$(echo ${LINE} | cut -f 9 -d ":")
#Find report
RPTFILE=$(find ${REPORT_DIR} -name "${REPORT}*.csv")
#Determine Search Function and use
SEARCHFUNC=$(echo ${LINE} | cut -f 8 -d ":")
case ${SEARCHFUNC} in
1) search1 ;;
2) search2 ;;
3) search3 ;;
4) search3 ;;
esac
done