Unexpected Token Error `;;'

Hello all,

Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it.

7  ##*******************************************************************************************************
     8  ##  **********  FUNCTION USAGE  ***********
     9  ##*******************************************************************************************************
    10  ##
    11
    12  # Script name without path
    13
    14  BASENAME=${0##*/}
    15
    16  #Default Config & Log Path
    17
    18  LOCATION=/home/63623AD
    19  #
    20  #
    21  #
    22  #The INFILE is going to use during the SSH
    23
    24  liveFilePattern="${LOCATION}/config/app.properties.live.txt"
    25  archFilePattern="${LOCATION}/config/app.properties.archive.txt"
    26
    27  #The String Search File
    28
    29  myString="${LOCATION}/config/stringFile.txt"
    30
    31  # Functional Usage
    32
    33  usage() {
    34          echo
    35          echo "USAGE"
    36          echo "  $BASENAME  <OPTION> <SERVICE_NAME>  "
    37          echo
    38          echo "<SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in DIR.
    39                   <OPTION>
    40                    <-L | -l>    = Searching from the LIVE LOGS.
    41                   <-A | -a>    = Searching from the ARCHIVE LOGS.
    42
    43          if [ "$1" != 0 ]|| [ "$1" != 0 ] then
    44          echo
    45          echo "  Check USAGE for correct Parameters  "
    46          fi
    47          exit 1
    48          }
    49          echo
    50          echo "**********************************************************************"
    51          echo " Searching for the  ${2} XML in Request "
    52          echo "**********************************************************************"
    53          echo
    54  # Check the  parameters
    55  #
    56  [ $# != 2 ] && usage
    57
    58  #Validate the Service Name from
    59  #
    60
    61  function FilePattern (){
    62  # Checking for the existence of Pattern File in the LOG DIR
    63
    64  fgrep "$2" ${FilePattern} > /dev/null || {
    65  echo  Service NOT Available
    66  exit 1
    67  }
    68
    69  function myString() {
    70  #Checking for the existence of the String in String File
    71
    72  fregrep ${mLine}  ${myString} > /dev/null || {
    73  echo String NOT found
    74  exit 1
    75  }
    76
    77  # Check the input parameters
    78  #
    79     case $1 in
    80
    81           -L | -l)
    82              myString="${LOCATION}/config/stringFile.txt"
    83              echo " Searching for the search String from "${liveFilePattern}" "
    84              while read mLine
    85              do
    86              egrep -i "${mLine}" "${liveFilePattern}"
    87              echo "++++++++++++++++++++++++++++++++++++++++++"
    88              echo "Searching for the line :----- $mLine from Live  LOGS"
    89              echo "++++++++++++++++++++++++++++++++++++++++++"
    90              done < "${myString}"
    91
    92          ;;
    93           -A | -a)
    94              echo " Searching for the search String from "${archFilePattern}"
    95              while read mLine
    96              do
    97              gzegrep -i "${mLine}" "${archFilePattern}"
    98              echo "++++++++++++++++++++++++++++++++++++++++++"
    99              echo "Searching for the line :----- $mLine from Archive LOGS"
   100              echo "++++++++++++++++++++++++++++++++++++++++++"
   101              done < "${myString}"
   102          ;;
   103           *)
   104                  usage
   105                  echo " Please check for correct Parameter from the Usage "
   106          ;;
   107      esac

The Error is

./XMLsearch.sh getservicebyname
./XMLsearch.sh: line 102: syntax error near unexpected token `;;'
./XMLsearch.sh: line 102: `        ;;'

Remove ;; from last case.

*)
   104                  usage
   105                  echo " Please check for correct Parameter from the Usage "
   106          ;;
   107      esac

I removed ;; from the case , but still seeing the same.

  ;;
         *)
                usage
                echo " Please check for correct Parameter from the Usage "
    esac



~
"XMLsearch.sh" 109 lines, 3041 characters
$ ./XMLsearch.sh servicebyname
./XMLsearch.sh: line 102: syntax error near unexpected token `;;'
./XMLsearch.sh: line 102: `        ;;'


I think this is your problem:

echo " Searching for the search String from "${archFilePattern}"

remove the middle double quote...

And we are missing some echo statements and quotes here:

38          echo "<SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in DIR.
    39                   <OPTION>
    40                    <-L | -l>    = Searching from the LIVE LOGS.
    41                   <-A | -a>    = Searching from the ARCHIVE LOGS.

Cleared the issue what methyl has asked .

But getting this error NOW

$ ./XMLsearch.sh servicebyname
./XMLsearch.sh: line 46: syntax error near unexpected token `fi'
./XMLsearch.sh: line 46: `        fi'

---------- Post updated at 03:25 AM ---------- Previous update was at 03:16 AM ----------

Above error is cleared, but found something new.

 ./XMLsearch.sh -L SERVICEBYNAME
**********************************************************************
 Searching for the  SERVICEBYNAME XML in Request
**********************************************************************

./XMLsearch.sh: line 104: syntax error: unexpected end of file
 
echo " Searching for the search String from "${archFilePattern}" "

That should be:

echo " Searching for the search String from ${archFilePattern} "

or

echo " Searching for the search String from \"${archFilePattern}\" "

You might have fixed this one already.

   43          if [ "$1" != 0 ]|| [ "$1" != 0 ] ; then

---------- Post updated at 13:43 ---------- Previous update was at 13:09 ----------

Also there are two alternative syntaxes to start a function:

function identifier {list;}
identifier () {list;}

One of these conforms to the syntax rules and two do not:

    33  usage() {
    61  function FilePattern (){
    69  function myString() {

Somewhere the script is not reading the input parameter & not searching the string in that file, rather its showing an error. Can anybody help me to figure out.

12  # Script name without path
    13
    14  BASENAME=${0##*/}
    15
    16  #Default Config & Log Path
    17
    18  LOCATION=/home/23456jg
    19  #
    20  #
    21  #
    22  #The INFILE is going to use during the SSH
    23
    24  liveFilePattern="${LOCATION}/config/app.properties.live.txt"
    25  archFilePattern="${LOCATION}/config/app.properties.archive.txt"
    26
    27  #The String Search File
    28
    29  myString="${LOCATION}/config/stringFile.txt"
    30
    31  # Functional Usage
    32
    33  usage() {
    34          echo
    35          echo "USAGE"
    36          echo "  $BASENAME  <OPTION> <SERVICE_NAME>  "
    37          echo
    38          echo "<SERVICE_NAME> = Enter the vaild SERVICE_NAME that exists in 76S DIR.
    39                  <-L | -l>    = Searching from the LIVE LOGS.
    40                  <-A | -a>    = Searching from the ARCHIVE LOGS."
    41          }
    42          echo
    43          echo "**********************************************************************"
    44          echo " Searching for the  ${2} XML in Request "
    45          echo "**********************************************************************"
    46          echo
    47  # Check the  parameters
    48  #
    49  [ "$#" != "2" ] && usage
    50
    51  #Validate the Service Name from
    52  #
    53
    54  function FilePattern (){
    55  # Checking for the existence of Pattern File in the LOG DIR
    56
    57  fgrep "$2" ${FilePattern} > /dev/null || {
    58  echo  Service NOT Available
    59  exit 1
    60  }
    61
    62  function myString() {
    63  #Checking for the existence of the String in String File
    64
    65  fregrep ${mLine}  ${myString} > /dev/null || {
    66  echo String NOT found
    67  exit 1
    68  }
    69
    70  # Check the input parameters
    71  #
    72     case $1 in
    73
    74           -L | -l)
    75              myString="${LOCATION}/config/stringFile.txt"
    76              echo " Searching for the search String from \"${liveFilePattern}\" "
    77              while read mLine
    78              do
    79              egrep -i "${mLine}" "${liveFilePattern}"
    80              echo "++++++++++++++++++++++++++++++++++++++++++"
    81              echo "Searching for the line :----- $mLine from Live  LOGS"
    82              echo "++++++++++++++++++++++++++++++++++++++++++"
    83              done < "${myString}"
    84
    85          ;;
    86           -A | -a)
    87              echo " Searching for the search String from \"${archFilePattern}\" "
    88              while read mLine
    89              do
    90              gzegrep -i "${mLine}" "${archFilePattern}"
    91              echo "++++++++++++++++++++++++++++++++++++++++++"
    92              echo "Searching for the line :----- $mLine from Archive LOGS"
    93              echo "++++++++++++++++++++++++++++++++++++++++++"
    94              done < "${myString}"
    95          ;;
    96           *)
    97                  usage
    98                  echo " Please check for correct Parameter from the Usage "
    99      esac
   100  exit


The content of LiveFilePattern is nothing but the File & Location

$ cat /config/app.properties.live.txt

Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log1"
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log2"
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log3"
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log4"  
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log5"

AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log1"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log2"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log3"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log4"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log5"

EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log1"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log2"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log3"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log4"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log5"

FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log1"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log2"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log3"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log4"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log5"

The content of ArchiveFilePattern is nothing but the Zipped File & its Location

Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log1*.log.gz"
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log2*.log.gz"
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log3*.log.gz"
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log4*.log.gz"  
Servicechoicepoint =  "/logs/Application/production/FSST/transaction/Servicechoicepoint_Log5*.log.gz"

AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log1*.log.gz"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log2*.log.gz"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log3*.log.gz"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log4*.log.gz"
AddAcctService ="/logs/Application/production/FSST/transaction/AddAcctService_Log5*.log.gz"

EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log1*.log.gz"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log2*.log.gz"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log3*.log.gz"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log4*.log.gz"
EquipmentService = "/logs/Application/production/FSST/transaction/EquipmentService_Log5*.log.gz"

FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log1*.log.gz"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log2*.log.gz"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log3*.log.gz"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log4*.log.gz"
FSSTError ="/logs/Application/production/FSST/transaction/FSSTError_Log5*.log.gz"

This is the Error Message .

./XMLsearch.sh -l Servicechoicepoint 

**********************************************************************
 Searching for the  Servicechoicepoint  XML in Request
**********************************************************************

./XMLsearch.sh: line 101: syntax error: unexpected end of file

Content of String File

$ cat stringFile.txt
<m:messageId>976625489</m:messageId>
<m:messageId>114972513</m:messageId>
<m:messageId>45287967</m:messageId>

.............................................

Line 61 and 69 need a }, not line 101 imo....

I agree with Scrutinizer.

Also:

Syntax of the functions
Lines 54 and 62 need to be the same syntax as line 33.

Orphan code
Lines 42-46 don't belong in any of the functions.

Functions not called
Apart from "usage" I can't see calls to the other two functions.

Function names and variable names the same.
FilePattern and $FilePattern
myString and $myString

Dubious inward redirect (willl not work)
83 done < "${myString}"
94 done < "${myString}"

Hi all,

But from the above , i corrected few error. Script is running with string trying to search from the File Pattern file , but not from the File it supposed. Can anybody sort out this, where the script is pointing to.

Any help will be much appreciative

$ bash -x XMLsearch.sh -l dp_querysubscriberinfoservice
+ BASENAME=XMLsearch.sh
+ LOCATION=/home/232425jg
+ liveFilePattern=/home/232425jg/config/app.properties.live.txt
+ archFilePattern=/home/232425jg/config/app.properties.archive.txt
+ myString=/home/232425jg/config/stringFile.txt
+ echo

+ echo '**********************************************************************'
**********************************************************************
+ echo '          Searching for the  ServicebyNameXML in Request                      '
          Searching for the  ServicebyNameXML in Request
+ echo '**********************************************************************'
**********************************************************************
+ echo

+ case $1 in
+ read mLine
+ egrep -i 414d51204450303141504420202020204c91dcdb2d7488c0 ''
egrep: can't open
+ echo 'Searching for the line :----- 414d51204450303141504420202020204c91dcdb2d7488c0 from Live  LOGS'
Searching for the line :----- 414d51204450303141504420202020204c91dcdb2d7488c0 from Live  LOGS
+ read mLine
+ exit

Can anyone able to correct above script, to redefine the search of the STRING from the Files , where Files Patterns resembles each other as given above.

For eg:

MSgID:8743287jjhs73498eojwe9834732h8302kdw8

The above string has to be searched from the input parameter "ServicebyName".
But in my log path i have five instance of these file as given below. When ever i provide these "ServicebyName" it should read & match from the FilePatternlist.txt file and should get me the result.

ls -ltr /logs/Application/production/FSST/transaction/ | grep -i ServicebyName

-rwx-r--r--  --------------------------- ServicebyName_Log1
-rwx-r--r--  --------------------------- ServicebyName_Log2
-rwx-r--r--  --------------------------- ServicebyName_Log3
-rwx-r--r--  --------------------------- ServicebyName_Log4
-rwx-r--r--  --------------------------- ServicebyName_Log5

When i run the script, it should start searching the STRING provided in stringFile.txt
from the LOG FILE Instances irrespectively in the log DIR .