Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-19-2011   -   Original Discussion by primaxx
primaxx's Unix or Linux Image
primaxx primaxx is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 28 October 2011, 2:45 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
[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 04:22 PM.. Reason: Solved
Sponsored Links
    #2  
Old Unix and Linux 09-19-2011   -   Original Discussion by primaxx
neutronscott's Unix or Linux Image
neutronscott neutronscott is offline Forum Advisor  
script kiddie
 
Join Date: Jun 2011
Last Activity: 21 September 2017, 10:02 PM EDT
Location: South Carolina, USA
Posts: 941
Thanks: 31
Thanked 304 Times in 282 Posts
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

Sponsored Links
    #3  
Old Unix and Linux 09-19-2011   -   Original Discussion by primaxx
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 13 December 2017, 10:16 AM EST
Location: Saskatchewan
Posts: 22,546
Thanks: 1,159
Thanked 4,286 Times in 3,955 Posts
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 Unix and Linux 09-19-2011   -   Original Discussion by primaxx
primaxx's Unix or Linux Image
primaxx primaxx is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 28 October 2011, 2:45 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unbelievable. It works!

Thank you both so very much, this has been a real headache to me!
Linux
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
BASH: Interactive "cp" (and "mv") in a loop SilversleevesX UNIX for Dummies Questions & Answers 2 03-14-2011 03:36 PM
Syntax error: word unexpected (expecting ")") figaro Shell Programming and Scripting 9 03-06-2009 03:18 PM
"syntax error near unexpected token `fi' " GIC1986 Solaris 4 09-19-2008 01:17 PM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 12:16 PM
"syntax error at line 21 :'done' unexpected." error message" ibroxy Shell Programming and Scripting 3 08-08-2007 07:45 AM



All times are GMT -4. The time now is 08:55 AM.