Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Bash (Ubuntu server): Syntax error: "|" unexpected in While-loop

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 09-19-2011
[Solved] Bash (Ubuntu server): Syntax error: "|" unexpected in While-loop

Hello forum,

I hope my problem is easy to solve for someone in here!

My main task is to copy a large amount of imap-accounts from one server to another. There is a tool (Perl) called imapsync which does the job exellent. Unfortunately I'm only able to run it on one account at a time.

After some heavy googling I learned I could make a shell script that, combined with a csv-file, does the job for me. Well, it turns out that was easier said than done. (I am by no means experienced in shell-scripting. -In fact; I have never made any scripts before...)

What I want the script to do:
As long as there is unread information in the csv-file, I want it to copy the imap-account AND create a logfile for that spesific account.

What the script does:
It gives me the error Syntax error: "|" unexpected...

The script looks like this:
Code:
#! /bin/sh
while IFS=';' read  u1 u2 p2
	do 
		imapsync --buffersize 8192000 --nosyncacls --subscribe --syncinternaldates --debug --host1 mail.server.com --user1 "$u1" --authuser1 administrator@server.com --password1 Password --ssl1 --port1 993 --host2 mail.server.net --user2 "$u2" --password2 "$p2"  --authmech2 PLAIN --ssl2 --port2 993; | tee "$u1".log \
	done < userinfo.csv
exit

If anyone can tell me why this doesn't work and how I should solve it I would be very greatful!

Last edited by primaxx; 09-19-2011 at 03:22 PM.. Reason: Solved
# 2  
Old 09-19-2011
Remove the ';' before the '|' and the '\' at the EOL...?

Code:
while IFS=';' read  u1 u2 p2
	do 
		imapsync --buffersize 8192000 --nosyncacls --subscribe --syncinternaldates --debug --host1 mail.server.com --user1 "$u1" --authuser1 administrator@server.com --password1 Password --ssl1 --port1 993 --host2 mail.server.net --user2 "$u2" --password2 "$p2"  --authmech2 PLAIN --ssl2 --port2 993 | tee "$u1".log
	done < userinfo.csv
exit

# 3  
Old 09-19-2011
You've got ; | If you want to pipe, you shouldn't end in ;, because ; means "end this command and start a new one".

Also, that \ in the middle of the line probably isn't doing what you want. It probably was there originally to combine two lines into one but now it's combining a line you don't want to be part of the statement, "done", into the statement. Ditch it.

I'd reorganize it as this:

Code:
#! /bin/sh
while IFS=';' read  u1 u2 p2
do 
	imapsync --buffersize 8192000 --nosyncacls --subscribe \
                --syncinternaldates --debug --host1 mail.server.com --user1 "$u1" \
                --authuser1 administrator@server.com --password1 Password --ssl1 \
                --port1 993 --host2 mail.server.net --user2 "$u2" --password2 "$p2" \
                --authmech2 PLAIN --ssl2 --port2 993 |
                        tee "$u1".log
done < userinfo.csv
exit

# 4  
Old 09-19-2011
Unbelievable. It works!

Thank you both so very much, this has been a real headache to me!
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error: "Syntax error; unexpected end of file" Pradeep_Raj Shell Programming and Scripting 1 03-15-2018 05:49 AM
Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file" getzeeshan BSD 3 06-09-2017 10:04 AM
"Help with bash script" - "License Server and Patch Updates" profileuser UNIX for Dummies Questions & Answers 25 04-01-2014 02:40 PM
Error"syntax error at line 15: `end of file' unexpected" millan Shell Programming and Scripting 5 05-31-2013 04:14 AM
Help with FTP Script which is causing "syntax error: unexpected end of file" Error mahi_mayu069 Shell Programming and Scripting 1 04-25-2013 07:27 AM
Help with error "syntax error: unexpected end of file" mahi_mayu069 Shell Programming and Scripting 2 04-25-2013 07:03 AM
Syntax error near unexpected token `"Hit <ENTER> to continue:"' lathigara Shell Programming and Scripting 7 07-31-2012 05:52 PM
Syntax error: word unexpected (expecting ")") figaro Shell Programming and Scripting 9 03-06-2009 02:18 PM
"syntax error near unexpected token `fi' " GIC1986 Solaris 4 09-19-2008 12:17 PM
"syntax error at line 21 :'done' unexpected." error message" ibroxy Shell Programming and Scripting 3 08-08-2007 06:45 AM


All times are GMT -4. The time now is 07:00 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password