user1654528 user1654528 - 4 months ago 20
Bash Question

BASH how to wait for mysql LOAD DATA LOCAL INFILE to complete

I have the following command in a BASH script. How can I check whether the command has completed uploading the file?

$(mysql -h "${1}" --user="${2}" --password="${3}" -D"${4}" --skip-column-names --local-infile=1 -e "LOAD DATA LOCAL INFILE '$tempFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' " )

Answer

You can execute the query and then check the status by looking at $?:

mysql -h "${1}" --user="${2}" --password="${3}" -D"${4}"   --skip-column-names --local-infile=1 -e "LOAD DATA LOCAL INFILE '$tempFile' INTO TABLE $tableName FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' "
if [ $? ... ]; then do_something
Comments