skij
asked on
Shell Script with Loop Problem
What is wrong with by shell script?
Syntax error: end of file unexpected
#!/bin/bash
numberFirst=1
jump=100
max=500
while [ $numberFirst -le $max ]
do
numberLast=$(( numberFirst+$jump-1 ))
curl 'http://my_domain.com/new_crm/migration/db_Contacts.asp?numberFirst='$numberFirst'&numberLast='$numberLast -o '/data/x'$numberFirst'_'$numberLast'.txt'
/usr/local/bin/mysql --defaults-file=/conf/m.conf << EOF
use mydb;
LOAD DATA LOCAL INFILE '/data/x'$numberFirst'_'$numberLast'.txt'
INTO TABLE Contacts
CHARACTER SET UTF8
FIELDS TERMINATED BY '###|COLUMN|###'
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '###|ROW|###';
EOF
numberFirst=$(( numberFirst+$jump ))
done
I get an error:Syntax error: end of file unexpected
ASKER
I tried that, I deleted the EOF line and created it again using nano making sure that there was not extra whitespace and I still get the error!
So check line 12 too, "EOF" there should not be followed by extra whitespace either.
The single quote after "-o" in the "curl line looks misplaced. It might not be the cause of the error, but I'd write it like this:
The single quote after "-o" in the "curl line looks misplaced. It might not be the cause of the error, but I'd write it like this:
curl 'http://my_domain.com/new_crm/migration/db_Contacts.asp?numberFirst='$numberFirst'&numberLast='$numberLast' -o /data/x'$numberFirst'_'$numberLast'.txt'
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It is still not working! Perhaps I have too many moving parts to solve any single problem.
I have broken it into a smaller piece. Is there any way to do a simple MySQL query inside of a loop?
I have broken it into a smaller piece. Is there any way to do a simple MySQL query inside of a loop?
#!/bin/bash
numberFirst=1
jump=100
max=500
while [ $numberFirst -le $max ]
do
numberLast=$(( numberFirst+$jump-1 ))
/usr/local/bin/mysql --defaults-file=/conf/m.conf << EOF
SELECT (1)
EOF
numberFirst=$(( numberFirst+$jump ))
done
This smaller piece works perfectly for me (5 iterations).
Do you still get the same error?
Do you still get the same error?
ASKER
Yes, I get the same error:
Syntax error: end of file unexpected (expecting "do")
I am on a FreeBSD box.
Syntax error: end of file unexpected (expecting "do")
I am on a FreeBSD box.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please delete that line and add it again, just "EOF" starting in column 1 followed by "newline" and nothing else.