Operating System - HP-UX
1752518 Members
5214 Online
108788 Solutions
New Discussion юеВ

Re: Syntax error at line 23 : `<' is not matched.

 
SOLVED
Go to solution
TinaAgarwal
New Member

Syntax error at line 23 : `<' is not matched.

Hi,
I am getting error 'Syntax error at line 23 : `<' is not matched.' in below script. Please tell me the solution for it.

This script takes comma seperated file names and ftp to different machine to get those files.

If anybody have a better script for the problem statement, sharing is much appreciated!

#!/bin/sh
set -x

#takes the input
strn=$1

#counts the number of files in string
count=`echo $strn | awk -F, {'print NF'}`

#declarations
i=1
hostname="tblusr47"
username="abansal"
password="abansal"

while [ $i -le $count ]
do

str[$i]=`echo $strn | cut -d, -f${i}`

cd /home/tagarwal/files

ftp -i -n $hostname< quote USER $username
quote PASS $password

binary
cd /rockblock/batch/ROCKHOLD/import
get ${str[$i]}
#echo ${str[$i]}
i=`expr $i + 1`
quit

done
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: Syntax error at line 23 : `<' is not matched.

Just guessing, but in this line

ftp -i -n $hostname<
I would expect there would have to be a concluding EOFTP, which I don't see.


Pete

Pete
TinaAgarwal
New Member

Re: Syntax error at line 23 : `<' is not matched.

Thanks Pete. if you mean quitting from FTP then I have 'Quit' in the last. Please correct me if I am wrong..
Dennis Handly
Acclaimed Contributor

Re: Syntax error at line 23 : `<' is not matched.

As Pete said, you are missing your here-document terminator: EOFTP
ftp -i -n $hostname<USER $username $password
binary
cd /rockblock/batch/ROCKHOLD/import
get ${str[$i]}
bye
EOFTP
(( i += 1 ))
done
TinaAgarwal
New Member

Re: Syntax error at line 23 : `<' is not matched.

I have modified the code as per your suggestion but still the problem persists. Below is the modified script..
#!/bin/sh
set -x

#takes the input
strn=$1

#counts the number of files in string
count=`echo $strn | awk -F, {'print NF'}`

#declarations
i=1
hostname="tblusr47"
username="abansal"
password="abansal"

while [ $i -le $count ]
do

str[$i]=`echo $strn | cut -d, -f${i}`

cd /home/tagarwal/files

ftp -i -n $hostname< USER $username $password
#quote USER $username
#quote PASS $password

binary
cd /rockblock/batch/ROCKHOLD/import
get ${str[$i]}
#echo ${str[$i]}
bye
EOFTP

((i+=1))
#i=`expr $i + 1`
done

I apologize if I am not able to understand as I am not very proficient in scripting and need ur help..
Bill Hassell
Honored Contributor

Re: Syntax error at line 23 : `<' is not matched.

Here are a few notes to help with the script


> set -x

Rather than permanently store the trace option in the script, you can run the script with the option set or not set, as in:

$ sh -x myscript

> #takes the input
> strn=$1

SInce the first parameter is all your files, rather than use an array to store them (str[]), just replace the comma with a space and then create the while loop with a for loop:

FILES=$(echo $1 | tr -s "," " ")
for FILENAME in $FILES
do
...

> #counts the number of files in string
> count=`echo $strn | awk -F, {'print NF'}`

count is no longer needed. Note that scripts are much easier to read if all variables are UPPERCASE and with meaningful names ($COUNTER rather than $i)

> str[$i]=`echo $strn | cut -d, -f${i}`

Not needed since $FILENAME will have each new file. Note that `` (grave accents) are deprecated as too limited and far too easy to confuse with ''. The construct $() is preferred.

> cd /home/tagarwal/files

Not needed inside the loop...just cd before the loop starts.

> ftp -i -n $hostname<
The ftp -i option is not necessary since you are only ftp'ing one file at a time.
The syntax error is with <
ftp -i -n << EOFTP

> #quote USER $username
> #quote PASS $password

The # character is not a comment inside ftp. Each of these lines will generate an ftp error message.

Here is the script simplified:
===========================================

#!/bin/sh
set -u # (prevents undetected spelling errors)

[[ $# -ne 1 ]] &&
echo "wrong parameter count" &&
exit

HOSTNAME="tblusr47"
USERNAME="abansal"
PASSWORD="abansal"
cd /home/tagarwal/files

FILES=$(echo $1 | tr -s "," " ")
for FILENAME in $FILES
do
echo "Transferring $FILENAME"
ftp -i -n $HOSTNAME << EOFTP
binary
get $FILENAME
bye
EOFTP

done
echo "Completed"


Bill Hassell, sysadmin
mvpel
Trusted Contributor

Re: Syntax error at line 23 : `<' is not matched.

The "<<" operator is sensitive to whitespace, apparently due to the way in which the shell parser works.

Change this:
ftp -i -n $hostname<
... to this:

ftp -i -n $hostname <
And it'll work.
Bill Hassell
Honored Contributor
Solution

Re: Syntax error at line 23 : `<' is not matched.

Oops, forgot the username, password line for ftp:

#!/bin/sh
set -u # (prevents undetected spelling errors)

[[ $# -ne 1 ]] &&
echo "wrong parameter count" &&
exit

HOSTNAME="tblusr47"
USERNAME="abansal"
PASSWORD="abansal"
cd /home/tagarwal/files

FILES=$(echo $1 | tr -s "," " ")
for FILENAME in $FILES
do
echo "Transferring $FILENAME"
ftp -i -n $HOSTNAME << EOFTP
user $USERNAME $PASSWORD
binary
get $FILENAME
bye
EOFTP

done


Bill Hassell, sysadmin
TinaAgarwal
New Member

Re: Syntax error at line 23 : `<' is not matched.

Thanks bill and every body for the help. It worked now.
T. M. Louah
Esteemed Contributor

Re: Syntax error at line 23 : `<' is not matched.

We appreciate everyone's contibutions,that's the spirit of Forums such as ITRC's..Please assign points
Little learning is dangerous!