【问题标题】:waiting for mysql query to terminate in bash script等待mysql查询在bash脚本中终止
【发布时间】:2014-01-17 04:28:46
【问题描述】:

我正在尝试编写一个 bash 脚本,该脚本遍历文本文件中的一系列 mysql 查询。我尝试使用以下脚本

#!/bin/bash
# Process files

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

但它失败了,因为 nohup.out 在文本文件中的查询完成之前不存在。为暂停选择固定持续时间是不可行的,因为查询的长度是可变的。如何暂停脚本直到查询完成?

【问题讨论】:

  • 那么,不要把它放在后台。消除&amp;

标签: mysql linux bash


【解决方案1】:

使用wait 命令

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

或者,不要在后台运行命令

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

【讨论】:

    猜你喜欢
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多