-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_experiments.sh
executable file
·102 lines (88 loc) · 2.25 KB
/
execute_experiments.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
# parse arguments
print_usage() {
echo "Usage: execute_experiments.sh [OPTIONS] tracker_configs_dir environment_config_file"
echo ""
echo "Options:"
echo " -h, --help show this message"
echo " -b emit a periodic beep sound when experiments are finished."
}
env_config=""
trackers_config_dir=""
do_beep=false
for arg in $@
do
if [[ "$arg" == "-h" ]]
then
print_usage
exit 0
elif [[ "$arg" == "-b" ]]
then
do_beep=true
elif [[ -z "$trackers_config_dir" ]]
then
trackers_config_dir="$arg"
elif [[ -z "$env_config" ]]
then
env_config="$arg"
else
echo "ERROR: Too many arguments!"
print_usage
exit 1
fi
done
if [[ -z "$env_config" ]] || [[ -z "$trackers_config_dir" ]]
then
echo "ERROR: Missing arguments!"
print_usage
exit 1
fi
if [[ ! -f "$env_config" ]]
then
echo "ERROR: '$env_config' not found - no such file!"
exit 1
fi
if [[ ! -d "$trackers_config_dir" ]]
then
echo "ERROR: '$trackers_config_dir' not found - no such directory!"
exit 1
fi
log_dir=$(cat "$env_config" | grep 'log_dir:')
log_dir=${log_dir#*log_dir:}
log_dir=$(echo "$log_dir" | sed -e 's/^[[ \t]]*//')
if [ -z $(type -t periodic_beep) ]; then
periodic_beep() {
echo "Hold Ctrl + C to quit."
while true;
do
paplay /usr/share/sounds/sound-icons/prompt
sleep 0.1
done
}
fi
echo "trackers directory is \"$trackers_config_dir\""
echo "environment file is \"$env_config\""
echo "log directory is \"$log_dir\""
mkdir -p "$log_dir"
for conf in "$trackers_config_dir/tracker"*.yaml; do
tags="$(cat $conf | grep 'tags:')" && \
tags=${tags#\#*tags:} && \
tags=$(echo "$tags" | sed -e 's/^[[ \t]]*//')
tags=${tags%\#*}
tags=$(echo "$tags" | sed -e 's/[ \t]*$//')
echo "executing \"$(basename $conf)\"..." && \
python hiob_cli.py -e "$env_config" -t "$conf" --silent
if ! [[ -z "$tags" ]]
then
for log in "$log_dir/hiob-execution-"*
do
echo "moving \"$log\" to \"$log_dir/[$tags]_$(basename $log)\""
mv "$log" "$log_dir/[$tags]_$(basename $log)"
done
fi
sleep 3
done
if $do_beep
then
periodic_beep
fi