1

I have files named like:

File1_01.sql
File1_02.sql
File2_01.sql
File2_02.sql

I need to run all the scripts for File1 first (but these can be done in parallel), then all the scripts for File2. What's my best way to do this?

Thanks,

-Scott

1
  • Do you need this in a script? Commented Jul 12, 2016 at 21:41

1 Answer 1

2

I don't know about "best" way, but I would probably not do it in parallel, just something simple like:

for sql in *.sql; do
   mysql options <"$sql"
done

If you need to do it in parallel:

for prefix in File1 File2; do
  for sql in ${prefix}_*.sql; do
    mysql options <"$sql" &
  done
  wait
done

This will first take the File1* files and start MySQL in parallel. Then wait for them to end before doing the same with all the File2* files.

2
  • The second one looks great, but it seems it doesn't interpret the wildcard? ./load_files.sh: line 5: File2_*.sql: No such file or directory Commented Jul 12, 2016 at 23:50
  • Never mind, I'm an idiot. It works great, thanks. Commented Jul 12, 2016 at 23:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.