-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_scripts.sh
More file actions
executable file
·54 lines (44 loc) · 1.48 KB
/
run_scripts.sh
File metadata and controls
executable file
·54 lines (44 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/zsh
# We use this array to keep track of backgrounded script_set PIDs
job_sets=()
for script_dir_name in "$@"; do
(
mkdir -p "$(dirname "$0")/logs"
export INCOMPLETE_JOB_LOG="$(dirname "$0")/logs/incomplete_jobs.log"
# We use this array to keep track of backgrounded script PIDs
script_jobs=()
script_dir="$(dirname "$0")/$script_dir_name"
wait_for_jobs() {
failed=0
for job in $script_jobs; do
wait $job || let "failed+=1"
done
script_jobs=()
if [ "$failed" != "0" ]; then
exit 1
fi
}
for script in $script_dir/*.sh; do
script_name=$(basename "$script")
last_script_number=${script_number}
script_number=${script_name:0:2}
# Once we're into a new number-set (e.g. 01 -> 02) or more than 3 jobs, wait for jobs to finish
if [ "$script_number" != "$last_script_number" ] || (( ${#script_jobs[@]} > 3 )); then
wait_for_jobs
fi
# Runs the script by its path, and uses sed to prepend the name to its stdout
(
echo "$script_dir_name/$script_name" >> "$INCOMPLETE_JOB_LOG"
$(dirname $0)/run_script.sh "$script" |& sed -e "s/^/[${script_name:3:-3}] /"
sed -i '' "/$script_dir_name\/$script_name/d" "$INCOMPLETE_JOB_LOG"
return ${pipestatus[1]}
) & script_jobs+="$!"
done
wait_for_jobs
) & job_sets+="$!"
done
failed_sets=0
for job_set in $job_sets; do
wait $job_set || let "failed_sets+=1"
done
exit $failed_sets