ksh Script - Syntax error `done' unexpected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh Script - Syntax error `done' unexpected
# 1  
Old 11-10-2015
ksh Script - Syntax error `done' unexpected

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!

Code:
# 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

# 2  
Old 11-10-2015
Missing closing double quotes at:
Quote:
echo "${RPTFILE} has no detected errors." >> ${APPLOG}
several times.
This User Gave Thanks to Aia For This Post:
# 3  
Old 11-10-2015
You have a semicolon after the if in search4(). I also think I see it in other if's as well. You have a number of other issues. Separate your functions in single files and debug them, then combine them.


Code:

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} ]];                        <------------------------------- remove semicolon
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
}

# 4  
Old 11-10-2015
Quote:
Originally Posted by blackrageous
You have a semicolon after the if in search4(). I also think I see it in other if's as well. You have a number of other issues. Separate your functions in single files and debug them, then combine them.


Code:

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} ]];                        <------------------------------- remove semicolon
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
}

The semicolon is unusual, but OK there. It would be as if:
Code:
if [[ ${RPTFIELD} = ${STRING1} ]]; then
    echo "..."

# 5  
Old 11-10-2015
Thanks for the quick replies! So much frustration and googling for some double quotes. I will remember this for next time. Back to the trenches! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error: `]' unexpected

I am getting this error Syntax error: `]' unexpected. Did I do something wrong with elif? Does ksh not like double brackets? if ]; then #echo hi source ~/.bashrc; elif ]; then #echo hi source ~/.kshrc; fi (5 Replies)
Discussion started by: cokedude
5 Replies

2. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

3. Shell Programming and Scripting

Help with ksh syntax error Unexpected Fi

Issue resolved, thanks (6 Replies)
Discussion started by: dangell82
6 Replies

4. Shell Programming and Scripting

Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'

first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good. I appreciate... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

5. Shell Programming and Scripting

ksh syntax error: `(' unexpected

So I am trying to convert my bash script into ksh, and this is what I have in the file so far: #!/bin/ksh login() { if then sendcmd BETA else sendcmd "$(xxd -c 32 -g 0 ${ZETA_ZETA} | awk '{print $2}')" fi } But when I run it: $ ./test.sh ... (1 Reply)
Discussion started by: guitarscn
1 Replies

6. Shell Programming and Scripting

script syntax error: unexpected end of file

Need help. I cannot find the reason for this error: here is the script (6 Replies)
Discussion started by: Lenora2009
6 Replies

7. Shell Programming and Scripting

Urgent: Script.sh: syntax error at line 72: `PROGRESS=$' unexpected

I have written a shell script to Automatically FTP a file. The script runs fine when doing it manually but when I schedule it using a crontab it gives me an error. . . . echo "-----------------Starting File FTP---------------------" >> $PROS_LOAD_LOG echo "open X.XX.XX.XXX" >>... (13 Replies)
Discussion started by: tanhajoy
13 Replies

8. Shell Programming and Scripting

Help on shell script : syntax error at line 62: `end of file' unexpected

Hi All, I have written a korn script (code pasted below). It is giving the error while debugging "new.sh: syntax error at line 62: `end of file' unexpected". I have re-written the whole code in VI and explored all help related to this error on this Unix forum and tried it. Somehow, I could... (7 Replies)
Discussion started by: schandrakar1
7 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. Shell Programming and Scripting

sh: syntax error: `...' unexpected???

Hello all, I want to create a script that polls every hour a directory for the existence of a file. The file I look for is a `token` dropped by an external process at the completion of a successful FTP process. I wrote this script `checkfile.ksh`: #!/usr/bin/ksh if ] then mailx... (5 Replies)
Discussion started by: alan
5 Replies
Login or Register to Ask a Question