Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: wait()ing for a job



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.



Messages sorted by: Reverse Date, Date, Thread, Author