Mark C
Mark C

Reputation: 391

waiting for mysql query to terminate in bash script

I am trying to write a bash script that iterates through a series of mysql queries in text files. I tried using the following script

#!/bin/bash
# Process files

for x in {1...8}
do
    nohup mysql < coauthorquery$x.txt &
    mv nohup.out coauthor$x.csv
done

But it fails because nohup.out isn't present until the completion of the query in the text file. Selecting a fixed duration for a pause is not feasible because length of the query is variable. How do I pause the script until the query is complete?

Upvotes: 2

Views: 1233

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

Use the wait command

nohup mysql < coauthorquery$x.txt &
wait
mv nohup.out coauthor$x.csv

Or, don't run the command in the background

nohup mysql < coauthorquery$x.txt
mv nohup.out coauthor$x.csv

Upvotes: 2

Related Questions