I've got this simple script below to stream compressed MySQL dumps to Amazon S3 bucket in parallel:
#!/bin/bash
COMMIT_COUNT=0
COMMIT_LIMIT=2
for i in $(cat list.txt); do
echo "$i "
mysqldump -B $i | bzip2 -zc | gof3r put -b s3bucket -k $i.sql.bz2 &
(( COMMIT_COUNT++ ))
if [ ${COMMIT_COUNT} -eq ${COMMIT_LIMIT} ]; then
COMMIT_COUNT=0
wait
fi
done
if [ ${COMMIT_COUNT} -gt 0 ]; then
wait
fi
The output looks like this:
database1
database2
duration: 2.311823213s
duration: 2.317370326s
Is there a way to print this on one line for each dump?
database1 - duration: 2.311823213s
database2 - duration: 2.317370326s
The echo -n
switch doesn't help in this case.
EDIT: Wed May 6 15:17:29 BST 2015
I was able to achieve expected results based on accepted answer:
echo "$i -" $(mysqldump -B $i| bzip2 -zc | gof3r put -b s3bucket -k $i.sql.bz2 2>&1) &
- however a command that is running in a subshell is not returning exit status to a parent shell because it's running in parallel so I'm not able to verify if it succeed or failed.
&
at the end ofmysqldump ..
command.echo "$i "
byecho -n "$i "
.echo
.