LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   While loop in SSH command (https://www.linuxquestions.org/questions/linux-newbie-8/while-loop-in-ssh-command-886561/)

gburton 06-15-2011 01:17 PM

While loop in SSH command
 
I am having trouble getting the while loop to execute in the ssh command:

ssh $USERID@serverX "while read line do echo $line done<$list_dir/cost_feed.lst.old"

Error: bash: -c: line 1: syntax error: unexpected end of file

I have managed to use simpler commands with ssh like:
ssh $USERID@serverX "pwd; cp x y"

I expect that I need to add some combination of escape characters or semicolons, but if anyone can point me in the right direction, i would appreciate it.

Skaperen 06-15-2011 01:23 PM

You need a couple semicolons in the right places:

Code:

ssh $USERID@serverX "while read line; do echo $line; done<$list_dir/cost_feed.lst.old"

colucix 06-15-2011 01:32 PM

I'd also change the double quotes with single quotes to protect the $ sign from the local shell.

gburton 06-15-2011 02:29 PM

Thanks, that worked.


All times are GMT -5. The time now is 12:02 AM.