#!/bin/bash if [[ $# -ne 1 || "$1" == '-h' || "$1" == '--help' ]] then echo 'Usage: ia-wait-item-tasks IDENTIFIER' echo 'Waits until the Internet Archive item IDENTIFIER has no outstanding tasks.' echo 'Exits non-zero if there are errored tasks' exit 1 fi set -e while : do out="$(ia tasks "$1")" out="$(python3 -c 'import json, sys; {print(o["status"]) for o in map(json.loads, sys.stdin) if "status" in o}' <<<"${out}")" if [[ -z "${out}" ]] then break fi if grep -Fxq 'error' <<<"${out}" then exit 1 fi sleep 60 done