Created
May 9, 2015 04:09
-
-
Save colinmollenhour/514b99b347ef28a8d9f4 to your computer and use it in GitHub Desktop.
Invoke jobs in parallel and capture the output and exit statuses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################################### | |
# This script invokes all jobs in parallel and organizes the output by job | |
# | |
# Author: Colin Mollenhour | |
############################################################################### | |
[ -z "$1" ] && { echo "Usage: $0 <commands_list>"; exit 1; } | |
wd=$(pwd) | |
[ -f errors ] && rm -f errors | |
while read line; do | |
output=$wd/$(echo "$line" | md5sum - | awk '{print $1;}') | |
( | |
echo "COMMAND: $line" > $output | |
$line 2>&1 >> $output | |
status=$? | |
echo "-------------- Completed on $(date) with status $status" >> $output | |
[ $status -eq 0 ] || cat $output >> $wd/errors | |
) 2>&1 >> $output & | |
done < <(grep -v '^$\|^\s*\#' $1) | |
wait | |
[ -f errors ] && { echo "One or more tasks incurred errors:"; cat errors; exit 1; } | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment