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