Stuck with Unexpected EOF

Hi,

i have a script as below.

i'm using sun solaris 10.

Script :

#! /bin/sh
load() {
find /stage_area/loadfiles/telsims/test/ -type f -name "*$1" -print > /tmp/testfile.txt
fc=`cat /tmp/testfile.txt | wc -l | sed 's/ //g'`
if [ $fc = 0 ]; then
echo " Files Not Avaliable"
exit
else
#Count the Total Number of files in source folder and assign it to i
i=` ls -l /stage_area/loadfiles/telsims/test/*."$1" | wc -l | sed 's/ //g'`
# checking the condition that all file are avaliable or not
if [ $i =39 ]; then
while true
do
# checking if any data is still transfering thru FTP..
cp /stage_area/loadfiles/telsims/test/*."$1" /tmp/test
sleep 20
ls -l /stage_area/loadfiles/telsims/test/*."$1" | awk '{print $5}' > /export/home/pmutv/test/file1.txt
ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/test/file2.txt
result=`cmp /export/home/pmutv/test/file1.txt /export/home/pmutv/test/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
if [ $result = "differ" ]
then
echo " Transfer not yet completed-------->"
fstatus=incomplete
else
echo " Transfer Completed "
fstatus=complete
break;
fi
rm -rf /tmp/test/*."$1"
done
if [ $fstatus = "complete" ]
then
echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found" <email_removed> 
find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
Flf=`cat /tmp/tmpfile.txt | wc -l`
if [ "$Flf" = 1 ]; then
mv /export/home/time/*.flg /export/home/time/"$1".flg
fi
# Invoke script to start moving data to staging area /stage_area/pm/script/ImportsimCp.sh ControlSimTest.sh $1
# after successful completion do the todays load
 
while true
do
find /export/home/data -type f -name *.log -print > /tmp/test.txt
op=`cat /tmp/test.txt | cut -f5 -d"/"`
echo "$op"
if [ $op = "smLoadSimAktivitetMan.log" ]; then
echo "Log File Avaliable------> prev sess completed"
Today_Date=`date +"%y%m%d"`
DailyLoad $Today_Date
else
echo "Log file not available---> Prev Sess is on Process"
fi
done
fi
else
echo "Currently $i files are present" #| mailx -s "All files are not found" <email_removed> 
fi
fi
}
DailyLoad()
{
find /export/home/test/ -type f -name "*.$1" -print > /tmp/testfile.txt
Fcount=`cat /tmp/testfile.txt | wc -l`
if [ $Fcount = 0 ]; then
echo " Files Not Avaliable"
exit
 
#Count the Total Number of files in the testfile and assign it to i
 
# i=` ls -l /export/home/test/*."$1" | wc -l | sed 's/ //g'`
 
elif [ $Fcount = 39 ]; then
while true
do
cp /export/home/test/*."$1" /tmp/test
sleep 30
ls -l export/home/pmutv/*."$1" | awk '{print $5}' > /export/home/file1.txt
ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/file2.txt
result=`cmp /export/home/file1.txt /export/home/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
# echo "$result"
if [ $result = "differ" ]
then
echo " $1 Transfer not yet completed-------->"
else
echo " $1 Transfer Completed "
rm -rf /tmp/test/*."$1"
break;
fi
done
# checking the condition that all file are avaliable or not
echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found" <email_removed> 
   #Create a time stamp File with Today's date for controlling schedule / rename the existing file
              find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
              Flf=`cat /tmp/tmpfile.txt | wc -l`
              if [ $Flf != 0 ];then
                    mv /export/home/time/*.flg /export/home/time/"$1.flg
             fi

          # Invoke script to start moving data to staging area  /stage_area/pm/script/ImportsimCp.sh ControlSimTest.sh $Date
   else
            echo "Currently $Fcount files are present" #| mailx -s "All files are not found" <email_removed> 
 fi
}
#Consider today date as 25 May... the script will work under below scenario
#Scenario1:believing that 22nd load was completed on 23. 23 and 24 load was avaiable only on 25
#Scenario2:believing that 23rd load was completed on 24 and 24 load was avaiable only on 25

Today_Date=`TZ=GMT+24 date "+%Y%m%d"`  #25
prev_day=`TZ=GMT+24 date "+%Y%m%d"`  #24
day_to_previous=`TZ=GMT+48 date "+%Y%m%d"`  #23
back_log=`TZ=GMT+72 date "+%Y%m%d"`  #22

# below code is to get the last session date from informatica repository
ORACLE_VALUE=$prev_day
 
if [ $ORACLE_VALUE = $day_to_previous ]
          then
                business_tabel_VALUE=$back_log
 
        if [ $business_tabel_VALUE = $back_log ]
          then
             load $prev_day
        fi

elif[ $ORACLE_VALUE = $prev_day ]
   then
        business_tabel_VALUE=$day_to_previous

         if [ $business_tabel_VALUE = $day_to_previous ]
           then
               DailyLoad $Today_Date
         fi

  fi

DailyLoad()
{

is not closed with }

Always post your code inside the [code] tag

it is easy to read

When performing numeric condition checks use -eq equal, -ge greater than or equal, -gt greater than etc and leave a space around -eq or -ge etc. For string conditions check use =, != etc Sample example below..

if [ "$i" -eq 39 ]... # Numeric comparison
if [ "Ux" != "UX" ] ..

# String comparison

i'm getting error as follows while running this script.
:frowning:

line 158: unexpected EOF while looking for matching `"'
line 222: syntax error: unexpected end of file

add -x in the shebang line and execute and tell me the error message and you didnt post the full code.

 
#!/bin/sh -x

Hi,

The entire code and error message as follows.

#! /bin/sh -x
load() {
find /stage_area/loadfiles/telsims/test/ -type f -name "*$1" -print > /tmp/testfile.txt
fc=`cat /tmp/testfile.txt | wc -l | sed 's/ //g'`
if [ "$fc" -eq 0 ]; then
echo " Files Not Avaliable"
exit
else
#Count the Total Number of files in source folder and assign it to i
i=` ls -l /stage_area/loadfiles/telsims/test/*."$1" | wc -l | sed 's/ //g'`
# checking the condition that all file are avaliable or not
if [ "$i" -eq 39 ]; then
while true
do
# checking if any data is still transfering thru FTP..
cp /stage_area/loadfiles/telsims/test/*."$1" /tmp/test
sleep 20
ls -l /stage_area/loadfiles/telsims/test/*."$1" | awk '{print $5}' > /export/home/pmutv/test/file1.txt
ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/test/file2.txt
result=`cmp /export/home/pmutv/test/file1.txt /export/home/pmutv/test/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
if [ "$result" = "differ" ]
then
echo " Transfer not yet completed-------->"
fstatus=incomplete
else
echo " Transfer Completed "
fstatus=complete
break;
fi
rm -rf /tmp/test/*."$1"
done
if [ "$fstatus" = "complete" ]
then
echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found" venkat.ratnakaram@logica.com
find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
Flf=`cat /tmp/tmpfile.txt | wc -l`
if [ "$Flf" -eq 1 ]; then
mv /export/home/time/*.flg /export/home/time/"$1".flg
fi
# Invoke script to start moving data to staging area /stage_area/pm/script/ImportsimCp.sh ControlSimTest.sh $1
# after successful completion do the todays load
 
while true
do
find /export/home/data -type f -name *.log -print > /tmp/test.txt
op=`cat /tmp/test.txt | cut -f5 -d"/"`
echo "$op"
if [ "$op" = "smLoadSimAktivitetMan.log" ]; then
echo "Log File Avaliable------> prev sess completed"
Today_Date=`date +"%y%m%d"`
DailyLoad $Today_Date
else
echo "Log file not available---> Prev Sess is on Process"
fi
done
fi
else
echo "Currently $i files are present" #| mailx -s "All files are not found" venkat.ratnakaram@logica.com
fi
fi
}
DailyLoad()
{
find /export/home/test/ -type f -name "*.$1" -print > /tmp/testfile.txt
Fcount=`cat /tmp/testfile.txt | wc -l`
if [ "$Fcount" -eq 0 ]; then
echo " Files Not Avaliable"
exit
 
#Count the Total Number of files in the testfile and assign it to i
 
# i=` ls -l /export/home/test/*."$1" | wc -l | sed 's/ //g'`
 
elif [ "$Fcount" -eq 39 ]; then
while true
do
cp /export/home/test/*."$1" /tmp/test
sleep 30
ls -l export/home/pmutv/*."$1" | awk '{print $5}' > /export/home/file1.txt
ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/file2.txt
result=`cmp /export/home/file1.txt /export/home/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
# echo "$result"
if [ "$result" = "differ" ]
then
echo " $1 Transfer not yet completed-------->"
else
echo " $1 Transfer Completed "
rm -rf /tmp/test/*."$1"
break;
fi
done
# checking the condition that all file are avaliable or not
 
echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found"
#Create a time stamp File with Today's date for controlling schedule / rename the existing file
find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
Flf=`cat /tmp/tmpfile.txt | wc -l`
if [ "$Flf" -neq 0 ];then
mv /export/home/time/*.flg /export/home/time/"$1.flg
fi
 
# Invoke script to start moving data to staging area /stage_area/pm/script/ImportsimCp.sh ControlSimTest.sh $Date
else
echo "Currently $Fcount files are present" #| mailx -s "All files are not found" venkat.ratnakaram@logica.com
fi
}
#Consider today date as 25 May... the script will work under below scenario
#Scenario1:believing that 22nd load was completed on 23. 23 and 24 load was avaiable only on 25
#Scenario2:believing that 23rd load was completed on 24 and 24 load was avaiable only on 25
 
Today_Date=`TZ=GMT+24 date "+%Y%m%d"` #25
prev_day=`TZ=GMT+24 date "+%Y%m%d"` #24
day_to_previous=`TZ=GMT+48 date "+%Y%m%d"` #23
back_log=`TZ=GMT+72 date "+%Y%m%d"` #22
 
# below code is to get the last session date from informatica repository
ORACLE_VALUE=$prev_day
 
if [ "$ORACLE_VALUE" = "$day_to_previous" ]
then
business_tabel_VALUE=$back_log
 
if [ "$business_tabel_VALUE" = "$back_log" ]
then
load $prev_day
fi
 
elif[ "$ORACLE_VALUE" = "$prev_day" ]
then
business_tabel_VALUE=$day_to_previous
 
if [ "$business_tabel_VALUE" = "$day_to_previous" ]
then
DailyLoad $Today_Date
fi
 
fi

:wq
"final.sh" 221 lines, 6108 characters
bash-3.00# ./final.sh
./final.sh: line 209: unexpected EOF while looking for matching `"'
./final.sh: line 222: syntax error: unexpected end of file

just for your information

code tag should end with [/CODE]

---------- Post updated at 02:06 PM ---------- Previous update was at 02:02 PM ----------

your script shows as 221 lines, but you posted only 137 lines...

 
"final.sh" 221 lines, 6108 characters

And the error is there in 209 and 222

 
./final.sh: line 209: unexpected EOF while looking for matching `"'
./final.sh: line 222: syntax error: unexpected end of file
1 Like

Hi,

sorry for the previous mail..

 
1 #! /bin/sh -x
2
3 load() {
4
5 find /stage_area/loadfiles/telsims/test/ -type f -name "*$1" -print > /tmp/testfile.txt
6
7 fc=`cat /tmp/testfile.txt | wc -l | sed 's/ //g'`
8
9 if [ "$fc" -eq 0 ]; then
10
11 echo " Files Not Avaliable"
12 exit
13 else
14
15 #Count the Total Number of files in source folder and assign it to i
16
17 i=` ls -l /stage_area/loadfiles/telsims/test/*."$1" | wc -l | sed 's/ //g'`
18
19 # checking the condition that all file are avaliable or not
20
21 if [ "$i" -eq 39 ]; then
22
23 while true
24
25 do
26 # checking if any data is still transfering thru FTP..
27
28 cp /stage_area/loadfiles/telsims/test/*."$1" /tmp/test
29
30 sleep 20
31
32 ls -l /stage_area/loadfiles/telsims/test/*."$1" | awk '{print $5}' > /export/home/pmutv/test/file1.txt
33
34 ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/test/file2.txt
35
36 result=`cmp /export/home/pmutv/test/file1.txt /export/home/pmutv/test/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
37
38 if [ "$result" = "differ" ]
39 then
40 echo " Transfer not yet completed-------->"
41 fstatus=incomplete
42
43 else
44 echo " Transfer Completed "
45 fstatus=complete
46 break;
47 fi
48 rm -rf /tmp/test/*."$1"
49 done
50
51 if [ "$fstatus" = "complete" ]
52
53 then
54
55 echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found" venkat.ratnakaram@logica.com
56
57 find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
58
59 Flf=`cat /tmp/tmpfile.txt | wc -l`
60
61 if [ "$Flf" -eq 1 ]; then
62
63 mv /export/home/time/*.flg /export/home/time/"$1".flg
64
65 fi
66 # Invoke script to start moving data to staging area /stage_area/pm/script/ImportsimCp.sh ControlSimTest.sh $1
67
68 # after successful completion do the todays load
69
70
71 while true
72 do
73
74 find /export/home/data -type f -name *.log -print > /tmp/test.txt
75 op=`cat /tmp/test.txt | cut -f5 -d"/"`
76 echo "$op"
77
78 if [ "$op" = "smLoadSimAktivitetMan.log" ]; then
79 echo "Log File Avaliable------> prev sess completed"
80 Today_Date=`date +"%y%m%d"`
81 DailyLoad $Today_Date
82 else
83 echo "Log file not available---> Prev Sess is on Process"
84 fi
85 done
86 fi
87 else
88
89 echo "Currently $i files are present" #| mailx -s "All files are not found" venkat.ratnakaram@logica.com
90 fi
91 fi
92 }
93
94 DailyLoad()
95 {
96
97 find /export/home/test/ -type f -name "*.$1" -print > /tmp/testfile.txt
98
99 Fcount=`cat /tmp/testfile.txt | wc -l`
100
101 if [ "$Fcount" -eq 0 ]; then
102
103 echo " Files Not Avaliable"
104 exit
105
106
107 #Count the Total Number of files in the testfile and assign it to i
108
109
110 # i=` ls -l /export/home/test/*."$1" | wc -l | sed 's/ //g'`
111
112
113 elif [ "$Fcount" -eq 39 ]; then
114
115 while true
116 do
117 cp /export/home/test/*."$1" /tmp/test
118
119 sleep 30
120
121 ls -l export/home/pmutv/*."$1" | awk '{print $5}' > /export/home/file1.txt
122 ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/file2.txt
123
124 result=`cmp /export/home/file1.txt /export/home/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
125 # echo "$result"
126
127 if [ "$result" = "differ" ]
128 then
129 echo " $1 Transfer not yet completed-------->"
130 else
131 echo " $1 Transfer Completed "
132 rm -rf /tmp/test/*."$1"
133 break;
134 fi
135
136 done
137
138 # checking the condition that all file are avaliable or not
139
140 echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found" root@xyz.com
141
142 #Create a time stamp File with Today's date for controlling schedule / rename the existing file
143
144 find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
145
146 Flf=`cat /tmp/tmpfile.txt | wc -l`
147
148 if [ "$Flf" -neq 0 ];then
149
150 mv /export/home/time/*.flg /export/home/time/"$1.flg
151 fi
152
153
154 # Invoke script to start moving data to staging area /stage_area/pm/script/ImportsimCp.sh ControlSimTest.sh $Date
155
156 else
157 echo "Currently $Fcount files are present" #| mailx -s "All files are not found" venkat.ratnakaram@logica.com
158
159 fi
160
161 }
162
163 #Consider today date as 25 May... the script will work under below scenario
164
165 #Scenario1:believing that 22nd load was completed on 23. 23 and 24 load was avaiable only on 25
166
167 #Scenario2:believing that 23rd load was completed on 24 and 24 load was avaiable only on 25
168
169
170 Today_Date=`TZ=GMT+24 date "+%Y%m%d"` #25
171
172 prev_day=`TZ=GMT+24 date "+%Y%m%d"` #24
173
174 day_to_previous=`TZ=GMT+48 date "+%Y%m%d"` #23
175
176 back_log=`TZ=GMT+72 date "+%Y%m%d"` #22
177
178
179 # below code is to get the last session date from informatica repository
180
181 ORACLE_VALUE=$prev_day
182
183
184
185 if [ "$ORACLE_VALUE" = "$day_to_previous" ]
186
187 then
188
189 business_tabel_VALUE=$back_log
190
191
192
193 if [ "$business_tabel_VALUE" = "$back_log" ]
194
195 then
196 load $prev_day
197
198 fi
199
200
201 elif[ "$ORACLE_VALUE" = "$prev_day" ]
202
203 then
204
205 business_tabel_VALUE=$day_to_previous
206
207
208 if [ "$business_tabel_VALUE" = "$day_to_previous" ]
209
210 then
211 DailyLoad $Today_Date
212
213 fi
214
215
216 fi

syntax error at line 217: `end of file' unexpected

when ever you write code, arrange the code properly, so that easily to read and debug.

in the below code (see last), why fi is there and in the next line else is there ?

fi
else

if [ "$i" -eq 39 ]; then
 while true
 do
  cp /stage_area/loadfiles/telsims/test/*."$1" /tmp/test
  sleep 20
  ls -l /stage_area/loadfiles/telsims/test/*."$1" | awk '{print $5}' > /export/home/pmutv/test/file1.txt
  ls -l /tmp/test/*."$1" | awk '{print $5}' > /export/home/test/file2.txt
  result=`cmp /export/home/pmutv/test/file1.txt /export/home/pmutv/test/file2.txt | cut -f3 -d" " | cut -f1 -d":"`
 
  if [ "$result" = "differ" ]
  then
   echo " Transfer not yet completed-------->"
   fstatus=incomplete
  else
   echo " Transfer Completed "
   fstatus=complete
   break;
  fi
 rm -rf /tmp/test/*."$1"
 done
 if [ "$fstatus" = "complete" ]
 then
  echo "Files Avalaible, Load Process is Starting Now" #| mailx -s "File Found" venkat.ratnakaram@logica.com
  find /export/home/time/ -type f -name *.flg -print > /tmp/tmpfile.txt
  Flf=`cat /tmp/tmpfile.txt | wc -l`
 
  if [ "$Flf" -eq 1 ]; then
   mv /export/home/time/*.flg /export/home/time/"$1".flg
  fi
 while true
 do 
  find /export/home/data -type f -name *.log -print > /tmp/test.txt
  op=`cat /tmp/test.txt | cut -f5 -d"/"`
  echo "$op"
  if [ "$op" = "smLoadSimAktivitetMan.log" ]; then
   echo "Log File Avaliable------> prev sess completed"
   Today_Date=`date +"%y%m%d"`
   DailyLoad $Today_Date
  else
   echo "Log file not available---> Prev Sess is on Process"
  fi
 done
fi
else

if [ "$i" -eq 39 ]; then
......
....
...
fi
else

Hi,

That fi closes the used in this way

if [ "$i" -eq 39 ]; then
if [ "$fstatus" = "complete" ]; then
-----------
-----------
--------
fi
else
----------
fi

execute the attached file and let me know

make sure there is a space after elif

 
elif [ "$ORACLE_VALUE" = "$prev_day" ]

Hi

it is giving the error...

./text.sh: syntax error at line 134: `end of file' unexpected

There are total of 133 lines...

make sure there is a space after elif

 
elif [ "$ORACLE_VALUE" = "$prev_day" ]

and first line should be

#!/bin/sh -x

no space after #!