1

I try to write a script that exporting some of the tables of a multi-site WordPress in shell script.

In my shell script, I start by retrieving the blogs IDs and the slug of each blog, and after some text processing I have a file that seems like that:

The file located under a folder called tmp in my working directory and the file name is blogs.csv

1,root-site
2,another-size
...
6,last-size

after that, I use the following code to iterate among the lines of that file and get the values from each line accordingly:

while IFS=',' read -r ID Slug; do
    # Iteration code here
done < "./tmp/blogs.csv"
IFS=$' \t\n'

Inside the loop, I have my code that producing the mysqldump command that extracting the required tables, and finally, after the command get produced I execute the following command to export the tables:

export_data="mysqldump -uroot -proot --opt ${schema} ${tables} > ${Slug}.sql"
sudo vagrant ssh --command "cd $export_folder && $export_data"

Now, white all information is correct, the script get's executed only once, and if I comment out the following line:

sudo vagrant ssh --command "cd $export_folder && $export_data"

Then the script executed for all blogs in my site.

So the question is, can I execute vagrant ssh --command more than once in a certain amount of time ? Do you think, is there any solution for that ?

UPDATE #1

In my mysqldump string I have add the option --debug-info and the result is the following:

Warning: Using a password on the command line interface can be insecure.
Connection to 127.0.0.1 closed.
Warning: Using a password on the command line interface can be insecure.

User time 0.00, System time 0.00
Maximum resident set size 2576, Integral resident set size 0
Non-physical pagefaults 860, Physical pagefaults 0, Swaps 0
Blocks in 0 out 1712, Messages in 0 out 0, Signals 0
Voluntary context switches 57, Involuntary context switches 49

Additionally if you see, in my log I have two Warning: messages, but not two Connection to 127.0.0.1 closed. messages, that means something wrong goes on with mysql dump ? I don't know. Can somebody help me ?

KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166
  • Requirement is not clear? Can you please clarify what you need? – SMA Dec 29 '14 at 17:27
  • My multi-site WordPress has 7 sites, so the while IFS=',' read -r ID Slug; do... loops for seven times with no problem if I have comment out the line sudo vagrant ssh --command "cd $export_folder && $export_data". If I un-comment out the line sudo vagrant ssh --command "cd $export_folder && $export_data", then the script executed only once. So the question is, why that happens – KodeFor.Me Dec 29 '14 at 17:32
  • 2
    use `set -vx` to turn on shell debug/trace. See if your line beginning with `sudo vagrant ...` looks correct when the parts get executed. Good luck. – shellter Dec 29 '14 at 17:33
  • `while IFS=, read ...; do` sets `IFS` only for the `read` built-in. You don't need to reset it after the loop. – Etan Reisner Dec 29 '14 at 18:34
  • Using a string for a command is a bad practice and in many cases *cannot* be done correctly. Use an array to construct a command. That being said if you need to embed that command *inside* a string that makes things harder (and using an array actually exacerbates the problem I believe) and you have to manually construct the string carefully. – Etan Reisner Dec 29 '14 at 18:36
  • 2
    `ssh` is eating your standard input. – Etan Reisner Dec 29 '14 at 18:37

0 Answers0