From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: wait()ing for a job
Date: Sat, 05 Jul 2014 12:56:29 -0700 [thread overview]
Message-ID: <140705125629.ZM12250@torch.brasslantern.com> (raw)
In-Reply-To: <140705103233.ZM12028@torch.brasslantern.com>
On Jul 5, 10:32am, Bart Schaefer wrote:
}
} One way to achieve what you want is to wrap each rsync job in a subshell
} which finishes with "print $?".
Here's a basic formula:
concurrent_rsync() {
local fd rsync_args rsync_status
local -A rsync_jobs
for rsync_args in "$@"
do
exec {fd}<<(rsync $=rsync_args ; print $?)
rsync_jobs[$fd]=$rsync_args
unset fd
done
while (( $#rsync_jobs ))
do
for fd in ${(k)rsync_jobs}
do
if read -t 0 rsync_status <&$fd
then
if (( rsync_status ))
then print "FAILED ($rsync_status): rsync $rsync_jobs[$fd]"
else print "SUCCEEDED: rsync $rsync_jobs[$fd]"
fi
noglob unset rsync_jobs[$fd]
fi
done
done
}
Note this will infinite-loop if any of the <<(rsync ...) substitutions
fails to print something to stdout, so additional defensive programming
is desirable.
Run it like:
concurrent_rsync '-avuz this there:that' '-bz whither:what where'
etc.
prev parent reply other threads:[~2014-07-05 19:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-05 5:07 meino.cramer
2014-07-05 17:32 ` Bart Schaefer
2014-07-05 19:56 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=140705125629.ZM12250@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).