2

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?

1
  • 1
    Don't put it in the background, then. eliminate the &. Commented Jan 17, 2014 at 4:29

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.