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'

Community
  • 1
  • 1
blocnt
  • 73
  • 1
  • 8
  • 1
    Your script has a bunch of syntax issues. Copy paste the script in http://www.shellcheck.net/ and try to fix the errors shown – Inian May 24 '16 at 15:02
  • LIKE '%cmd' ? I doubt that would be replaced by ${cmd} – LukStorms May 24 '16 at 15:41
  • The answer: http://stackoverflow.com/a/10265580/5520354 Also, is the data in the files coming from users? From [little Bobby Tables](https://xkcd.com/327/) maybe? – C14L May 24 '16 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 – blocnt May 25 '16 at 14:19
  • @C14L which data? The filelist.txt is created by other script, that lists the name of each file in that txt – blocnt May 25 '16 at 14:21
  • @blocnt The data in the `filelist.txt` file. – C14L May 25 '16 at 14:42
  • @blocnt the way Kenavoz solved it by using the ${line} variable to change the SQL statement. – LukStorms May 25 '16 at 14:56

0 Answers0