Reputation: 391
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
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