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 not figure it out.

Could you please help on this?

This script is written in SunOS 5.8 UNIX Server. Its details are:
$ uname -a
SunOS nwcmp100 5.8 Generic_117350-25 sun4u sparc SUNW,Sun-Fire-15000

When I run below script in debugger mode:
sh new.sh filename

It exits after if condition and displays error at next line of the last line of the code:

new.sh: syntax error at line 62: `end of file' unexpected

Thank you!!

Best Regards,
schandrakar1

#******************************
#!/usr/bin/ksh
#******************
# new.sh : It take a country_code file as input.
#It will read truncate files
# & monthly files from a specific directory in the sun server.
#Then it will log #all output or errors to a log file

set -vx

ME_StaggCountry_Codes=$1
Filename=`basename $0 .sh`
LOGPATH=${HOME}/camp/logs
LOGFILE=${LOGPATH}/${Filename}`date "+%d-%h-%Y%T`.log
exec 1> ${LOGFILE}
echo `date "+%d-%h-%Y_%T` : ----------- START of ${LOGFILE} --------------- 2>&1
echo
if [ $# -lt 1 ] || [ $# -gt 1 ] ; then
echo "Invalid Parameter list" 2>&1
echo "Usage : $0 <ME_StaggCountry_codes>" 2>&1
echo
echo `date "+%d-%h-%Y_%T` : ----------- END of ${LOGFILE} --------------- 2>&1
exit 1
elif [ $# -eq 1 ] ; then
echo "Input parameter file is : ${ME_StaggCountry_Codes}" 2>&1
fi

for code in `cat ${ME_StaggCountry_Codes}`
do
if [ ${code} != uk ] ; then
Filepath=/${code}rtlftp01/logs
elif [ ${code} = uk ] ; then
Filepath=/rtlftp01/logs
fi
echo
echo "For Country : ${code} 2>&1
echo "Truncate Files at path ${Filepath} are :" 2>&1
ls -ltr ${Filepath}/trunc* 2>&1
echo
echo "Monthly files at path ${Filepath} are :" 2>&1
ls -ltr ${Filepath}/monthly_mi* 2>&1
echo
echo "-----------------------" 2>&1
done
echo
echo `date "+%d-%h-%Y_%T` : ----------- Removing old log files --------------- 2>&1

find ${LOGPATH} -type f -name "${Filename}*.log" -mtime +2 | while read FILE
do
rm -i ${FILE} </dev/tty
done

echo `date "+%d-%h-%Y_%T` : ----------- END of ${LOGFILE} --------------- 2>&1

exec >/dev/tty

  1. Please use code tags, the forum offers them
  2. I copy&pasted your script and have 56 lines at most
  3. In the following line you don't close the "
  1. In many lines you use echo with ---- and : etc. which I prefer to surround by " or ', just to make sure I don't get errors.
  2. It can be helpful to use vim instead of vi and have the syntax highlighting turned on. It will show if you have forgotten to close brackets or quotes etc. Any other syntax highlighting capable editor will do too of course.

Hi Zaxxon,

Thank you very much for your wonderful replies !!

I am just trying them out.

Actually I did not paste the description (it actually has total 61 lines)

Hi,

I have incorporated your suggested changes. I do not have vim editorr on this SunOs 5.8 server.

I am still getting the same error. Please see the script run in debugger mode.

I am new to this forum. I did not get what did you mean by number 1 point in your reply mail.

Thank you so much for your help.

********************

$ sh new.sh ME_StaggCountry_codes

ME_StaggCountry_Codes=$1
ME_StaggCountry_Codes=ME_StaggCountry_codes
Filename=`basename $0 .sh`
+ basename new.sh .sh
Filename=new
LOGPATH=${HOME}/sandeep/camp/logs
LOGPATH=/export/home/rcampapp/sandeep/camp/logs
LOGFILE=${LOGPATH}/${Filename}`date "+%d-%h-%Y%T"`.log
+ date +%d-%h-%Y_%T
LOGFILE=/export/home/rcampapp/sandeep/camp/logs/new_11-Dec-2008_16:08:41.log

exec 1> ${LOGFILE}
+ exec

echo "`date "+%d-%h-%Y_%T"` : ----------- START of ${LOGFILE} ---------------" 2>&1
+ date +%d-%h-%Y_%T
+ echo 11-Dec-2008_16:08:41 : ----------- START of /export/home/rcampapp/sandeep/camp/logs/new_11-Dec-2008_16:08:41.log ---------------
echo
+ echo

if [ $# -lt 1 ] || [ $# -gt 1 ] ; then
echo "Invalid Parameter list" 2>&1
echo "Usage : $0 <ME_StaggCountry_codes>" 2>&1
echo
echo "`date "+%d-%h-%Y_%T"` : ----------- END of ${LOGFILE} ---------------" 2>&1
exit 1
elif [ $# -eq 1 ] ; then
echo "Input parameter file is : ${ME_StaggCountry_Codes}" 2>&1
fi
+ [ 1 -lt 1 ]
+ [ 1 -gt 1 ]
+ [ 1 -eq 1 ]
+ echo Input parameter file is : ME_StaggCountry_codes

for code in `cat ${ME_StaggCountry_Codes}`
do
if [ ${code} != uk ] ; then
Filepath=/${code}rtlftp01/logs
elif [ ${code} = uk ] ; then
Filepath=/rtlftp01/logs
fi
echo
echo "For Country : ${code} 2>&1
echo "Truncate Files at path ${Filepath} are :" 2>&1
ls -ltr ${Filepath}/trunc* 2>&1
echo
echo "Monthly files at path ${Filepath} are :" 2>&1
ls -ltr ${Filepath}/monthly_mi* 2>&1
echo
echo "-----------------------" 2>&1
done
echo
echo "`date "+%d-%h-%Y_%T"` : ----------- Removing old log files ---------------" 2>&1

find ${LOGPATH} -type f -name "${Filename}*.log" -mtime +2 | while read FILE
do
rm -i ${FILE} </dev/tty
done

echo "`date "+%d-%h-%Y_%T"` : ----------- END of ${LOGFILE} ---------------" 2>&1
exec >/dev/tty
new.sh: syntax error at line 62: `end of file' unexpected

Np, if you add [ code ] at the start of your code and [ /code ] at the end of your code in your post, you will have this neat blueish background that preservers formatting etc.
The blanks between the square brackets and the word code and /code may not be written to make it going into effect. It will look like this then:

test

No, I meant I copy & pasted your script to my system and it had only 56 lines :wink:

Can you please post the script as it is currently?

Hi Zaxxon,

Thank you for your reply!!

What I meant is that the script contains total 61 lines ( ie first 11 lines are about the type of script, name, input parameter...etc...it is just description about the script.) The actual script starts from line number 12...Please see the actual code pasted below in set nu mode.

Also please refer to the debugged mode script pasted above.

Thanks a lot for your continued help!!

    12
    13  set -vx
    14
    15  ME_StaggCountry_Codes=$1
    16  Filename=`basename $0 .sh`
    17  LOGPATH=${HOME}/sandeep/camp/logs
    18  LOGFILE=${LOGPATH}/${Filename}_`date "+%d-%h-%Y_%T"`.log
    19
    20  exec 1> ${LOGFILE}
    21
    22  echo "`date "+%d-%h-%Y_%T"` : ----------- START of ${LOGFILE} ---------------" 2>&1
    23  echo
    24
    25  if [ $# -lt 1 ] || [ $# -gt 1 ] ; then
    26          echo "Invalid Parameter list"  2>&1
    27          echo "Usage : $0 <ME_StaggCountry_codes>" 2>&1
    28          echo
    29          echo "`date "+%d-%h-%Y_%T"` : ----------- END of ${LOGFILE} ---------------" 2>&1
    30          exit 1
    31  elif [ $# -eq 1 ] ; then
    32          echo "Input parameter file is : ${ME_StaggCountry_Codes}" 2>&1
    33  fi
    34
    35  for code in `cat ${ME_StaggCountry_Codes}`
    36  do
    37          if [ ${code} != uk ] ; then
    38                  Filepath=/${code}rtlftp01/logs
    39          elif [ ${code} = uk ] ; then
    40                  Filepath=/rtlftp01/logs
    41          fi
    42          echo
    43          echo "For Country : ${code}     2>&1
    44          echo "Truncate Files at path ${Filepath} are :" 2>&1
    45          ls -ltr ${Filepath}/trunc*  2>&1
    46          echo
    47          echo "Monthly files at path ${Filepath} are :" 2>&1
    48          ls -ltr ${Filepath}/monthly_mi*  2>&1
    49          echo
    50          echo "-----------------------" 2>&1
    51  done
    52  echo
    53  echo "`date "+%d-%h-%Y_%T"` : ----------- Removing old log files ---------------" 2>&1
    54
    55  find ${LOGPATH} -type f -name "${Filename}*.log" -mtime +2  | while read FILE
    56  do
    57          rm -i ${FILE} </dev/tty
    58  done
    59
    60  echo "`date "+%d-%h-%Y_%T"` : ----------- END of ${LOGFILE} ---------------" 2>&1
    61  exec >/dev/tty

I removed the blanks in the [ code ] and [ /code ] tags so they are working in your previous post. I can't write them here without blanks since they will be substituted immediately.

        echo "For Country : ${code}     2>&1

.. is missing a closing double quote.

You should really start to edit files with some syntax highlighting editor, maybe on your PC and transfer them to your box. VIM or UltraEdit or... Maybe you can install VIM on your solaris box.

Great Zaxxon!!!

Thank you very much.

It is working now....Surely I will do as you have suggested.

Thank you once again.

Best Regards,
schandrakar1