Mercurial > hg > cc > azure
comparison workers/bin/timedWhich.sh @ 17:2a2c1fb03c54
first cut at http/https real trial, with month and year last-modified info too
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Fri, 19 Oct 2018 11:36:31 +0000 |
parents | |
children | 9631fca89cc6 |
comparison
equal
deleted
inserted
replaced
16:c3e9ad8a42cf | 17:2a2c1fb03c54 |
---|---|
1 #!/bin/bash | |
2 # Test script to split CC WAT files across threads | |
3 # to tabulate http vs. https by last-modified date: | |
4 # Usage: [echo file file_id] | timedWhich.sh id home [-t] numWorkerProcesses | |
5 # If -t, no random wait, just id seconds | |
6 # remove >>errs once tested | |
7 #set -e -o pipefail | |
8 echo $$ > test1.pid | |
9 proc=$1 | |
10 res=res$proc | |
11 home=$2 | |
12 shift 2 | |
13 function lrand { | |
14 # cheap bad little random number generator | |
15 echo $(( 1 + ($(openssl rand 1 | od -d | head -1 | tr -s ' ' | cut -f 2 -d ' ') % $1))) | |
16 } | |
17 if [ "$1" = "-t" ] | |
18 then | |
19 shift | |
20 pause=$proc | |
21 else | |
22 pause=$(lrand 60) | |
23 fi | |
24 wp=$1 | |
25 touch .running | |
26 function tryRead { | |
27 m=0 | |
28 set -o pipefail | |
29 until if [ $((m+=1)) -gt 5 ]; then echo "tried to read $1 5 times w/o success, giving up" 1>&2; return 1; fi && \ | |
30 curl -s --insecure -o - "$1"| zcat | fgrep msgtype=response | \ | |
31 { egrep -i '"WARC-Target-URI":"https?:' || : ;} > $2 | |
32 do | |
33 # try to avoid lockstep retries | |
34 echo ${PIPESTATUS[@]} 1>&2 | |
35 sleep $(lrand 10) | |
36 echo $(date) $2 retry number $m 1>&2 | |
37 done | |
38 set +o pipefail | |
39 } | |
40 trap "{ | |
41 #set -e -o pipefail | |
42 ln -s ../nohup.cc . | |
43 tar -czhf - CC* $res | \ | |
44 ssh -o StrictHostKeyChecking=no -q $home \"{ cd data | |
45 mkdir -p pdf/wat | |
46 cd pdf/wat | |
47 tar -xzf - ; } 2>>errs\" | |
48 rm -rf $res CC* ifile.txt *.pid | |
49 ( sleep 5 ; rm nohup.cc ) & | |
50 }" EXIT | |
51 mkdir -p $res | |
52 log=$res/log | |
53 # Don't all start at once | |
54 sleep $pause | |
55 echo \# $(date) > $log | |
56 pRes=0 | |
57 while read s id | |
58 do | |
59 url="https://commoncrawl.s3.amazonaws.com/$s" | |
60 ccm=${s##*/wat/} | |
61 cci=${ccm%%-ip*} | |
62 export ID=$id | |
63 echo \# $(date) "running |$proc|$home|$pause|$wp|$id|" >> $log | |
64 # Experimental retry loop | |
65 tryRead "$url" crawl$id | |
66 if [ -s crawl$id ] | |
67 then | |
68 echo \# $(date) $id $(wc -l crawl$id) >> $log | |
69 parallel --round-robin --pipe --block-size 2M -j $wp "_timedWhich.sh {#} >> $res/$cci.{#} 2>>$res/errs{#}" < crawl$id || echo "ppfailed $? ${PIPESTATUS[@]}" 1>&2 | |
70 else | |
71 echo "crawl$id empty" 1>&2 | |
72 fi | |
73 rm crawl$id | |
74 cat $res/$cci.* > $cci | |
75 done < ifile.txt 2>> $res/errs || pRes=$? | |
76 echo \# $(date) main loop exit code=$pRes >> $log | |
77 rm .running | |
78 | |
79 |