Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

Shell Script with Loop Problem

What is wrong with by shell script?
#!/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

Open in new window

I get an error:
Syntax error: end of file unexpected
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Seems there is one or more space(s) or some other whitespace character(s) following "EOF" in line 20

Please delete that line and add it again, just "EOF" starting in column 1 followed by "newline" and nothing else.
Avatar of skij

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:

curl 'http://my_domain.com/new_crm/migration/db_Contacts.asp?numberFirst='$numberFirst'&numberLast='$numberLast' -o /data/x'$numberFirst'_'$numberLast'.txt'

Open in new window

SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skij

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?
#!/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

Open in new window

This smaller piece works perfectly for me (5 iterations).
Do you still get the same error?
Avatar of skij

ASKER

Yes, I get the same error:
 Syntax error: end of file unexpected (expecting "do")

I am on a FreeBSD box.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial