0

The process is:

  1. I have a list of files (that keeps growing)
  2. The NAMES of these files are written in a txt file (filelist.txt)
  3. Each line of this txt will be a query to mysql return an output
  4. That output will be written on a txt file (output_file.txt)

ie, this is used to rename the files of 1. .

For example, the first line of txt file is "Yellow". Then it will search "Yellow" on mysql and return "Colour", which will be print on a txt.

My problem is on 3.. I'm using synology NAS. The bash code that I'm using to 3. isn't working:

#!/bin/sh

cat /volume1/blabla/filelist.txt | while read line
do
   #check if file exists
   if [ -f $line ] 
   then
        #turn the file into a command
        cmd=$(cat $line)
        mysql -h xx.xxx.xx.xx -u xx -pxx --execute="SELECT xx FROM xx WHERE lastName LIKE '%cmd' " > /volume1/blabla/output_file.txt;   
        fi
done

I'm getting:

sh: -c: line 10: syntax error near unexpected token 'done'

sh: -c: line 10: 'done'

7
  • 1
    Your script has a bunch of syntax issues. Copy paste the script in shellcheck.net and try to fix the errors shown Commented May 24, 2016 at 15:02
  • LIKE '%cmd' ? I doubt that would be replaced by ${cmd} Commented May 24, 2016 at 15:41
  • The answer: stackoverflow.com/a/10265580/5520354 Also, is the data in the files coming from users? From little Bobby Tables maybe? Commented May 24, 2016 at 16:52
  • @LukStorms Are there any alternatives to do that? I was using "cmd" to read each line of the txt and use that on the query Commented May 25, 2016 at 14:19
  • @C14L which data? The filelist.txt is created by other script, that lists the name of each file in that txt Commented May 25, 2016 at 14:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.