summaryrefslogtreecommitdiff
path: root/submit_to_web_batch
blob: b6775f682d2c137a145790da6c2c7fc8f48a95ea (plain)
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
#!/bin/bash

USER="$1"
[ -z "$USER" ] && echo "Provide a user as the first arg" && exit 1
[ -z "$HOST" ] && HOST="$(hostname -s)"
[ "$HOST" == "localhost" ] && HOST="$(hostname)"

CURL="`which curl`"
[ ! -x "$CURL" ] && echo "No curl, please install" && exit 1

RETRY_LOG=back.log

trap clear_backlog INT TERM
clear_backlog() {
    # The fun stuff goes here
    trap - INT TERM
    submit
}

submit() {
    echo "Buffer $buf"
    curl --max-time 5 --retry 10 --retry-delay 2 -F user="$USER" -F host="$HOST" \
        -F input_batch="$buf" "http://timhatch.com/projects/md5game/?a=submit&api=1"
    if [ $? -ne 0 ]; then
        echo "$buf" >> "$RETRY_LOG"
    fi
    buf=''
    i=0
}

i=0
buf=''
while read f; do
    echo "$f" | grep -q 'Benchmark\|Starting\|0x\|rough';
    if [ $? -eq 0 ]; then echo "> $f"; continue; fi;
    f="$(echo "$f" | sed -e 's/ .*//')"
    echo "$f queued"
    buf="$buf
$f"
    i=$(($i+1))
    if [ $i -gt 10 ]; then
        echo "Submitting..."
        submit
    fi
done

clear_backlog