0

Here is my script

#!/bin/bash

clear

PSQLSTART="INSERT INTO TABLE (Name, Description, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10, Field11, Field12, Field13, Field14, Field15, Field16, Field17, Field18) VALUES"

echo "What is the name of my CSV File?"
read CSVFILE

echo "What is the server IP?"
read INTIP

echo "What is the server username?"
read INTUSER

echo "What is the server password?"
read INTPW

while IFS=\| read -r col1 col2 col3 col4 col5; do
        sshpass -p "$INTPW" ssh -no StrictHostKeyChecking=no $INTUSER@$INTIP "echo $PSQLSTART$col1$col2$col3$col4$col5 >> /home/user/test.txt"

done < "$CSVFILE"

Here is what my CSV file looks like

("testname|","|test description|", 1, 1, 1, 0, 0, "|test_url|", "", 0, 0, "", 0, 0, 0, 0, 0, 0);

Here is my output and Error.

bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF8)
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `echo INSERT INTO TABLE (Name, Description, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10, Field11, Field12, Field13, Field14, Field15, Field16, Field17, Field18) VALUES("testname","test description", 1, 1, 1, 0, 0, "test_url|", "", 0, 0, "", 0, 0, 0, 0, 0, 0); >> /home/user/test.txt'

I looked up the errors but I could not find anything that's wrong with my script. Please help. Also I am new to bash scripting so this may be an easy fix, I just can't tell.

mc587
  • 1
  • ./script.sh thats how im running it – mc587 Mar 29 '21 at 00:43
  • You need three levels of quoting here; one to be applied (and removed) by the local shell (you have this), a second to be applied (and removed) by the remote shell (you do not have this), and a third that's part of the SQL syntax (you have this); see my answer to [this stackoverflow question](https://stackoverflow.com/questions/53465980/how-to-keep-parameter-with-spaces-when-running-remote-script-file-with-ssh/53472697). Also, that file isn't in CSV format, and the way you're reading it... I don't know what you're trying to do, but I'm pretty sure it's not what's happening. – Gordon Davisson Mar 29 '21 at 07:12

0 Answers0