-
Notifications
You must be signed in to change notification settings - Fork 1
/
runAll.sh
executable file
·50 lines (44 loc) · 1.6 KB
/
runAll.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
#!/bin/bash
########################################
############# CSCI 2951-O ##############
########################################
E_BADARGS=65
if [ $# -ne 3 ]
then
echo "Usage: `basename $0` <inputFolder/> <timeLimit> <logFile>"
echo "Description:"
echo -e "\t This script make calls to ./run.sh for all the files in the given inputFolder/"
echo -e "\t Each run is subject to the given time limit in seconds."
echo -e "\t Last line of each run is appended to the given logFile."
echo -e "\t If a run fails, due to the time limit or other error, the file name is appended to the logFile with --'s as time and result. "
echo -e "\t If the logFile already exists, the run is aborted."
exit $E_BADARGS
fi
# Parameters
inputFolder=$1
timeLimit=$2
logFile=$3
# Append slash to the end of inputFolder if it does not have it
lastChar="${inputFolder: -1}"
if [ "$lastChar" != "/" ]; then
inputFolder=$inputFolder$slash
fi
# Terminate if the log file already exists
[ -f $logFile ] && echo "Logfile $logFile already exists, terminating." && exit 1
# Create the log file
touch $logFile
# Run on every file, get the last line, append to log file
for f in $inputFolder*.*
do
echo "Running $f"
timeout $timeLimit ./run.sh $f > output.tmp
returnValue="$?"
if [[ "$returnValue" = 0 ]]; then # Run is successful
cat output.tmp | tail -1 >> $logFile # Record the last line as solution
else # Run failed, record the instanceName with no solution
echo Error
instance=$(basename "$f")
echo "{\"Instance\": \"$instance\", \"Time\": \"--\", \"Result\": \"--\"}" >> $logFile
fi
rm -f output.tmp
done