19 | | ~$ for ((i=1;i<20;i++)); do echo /user/h998/sample-$i.fa; done > sample-01.txt |
20 | | ~$ for ((i=20;i<40;i++)); do echo /user/h998/sample-$i.fa; done > sample-02.txt |
21 | | ~$ for ((i=40;i<60;i++)); do echo /user/h998/sample-$i.fa; done > sample-03.txt |
22 | | ~$ for ((i=60;i<80;i++)); do echo /user/h998/sample-$i.fa; done > sample-04.txt |
23 | | ~$ for ((i=80;i<100;i++)); do echo /user/h998/sample-$i.fa; done > sample-05.txt |
| 19 | ~$ for ((i=1;i<20;i++)); do echo /user/$(whoami)/sample-$i.fa; done > sample-01.txt |
| 20 | ~$ for ((i=20;i<40;i++)); do echo /user/$(whoami)/sample-$i.fa; done > sample-02.txt |
| 21 | ~$ for ((i=40;i<60;i++)); do echo /user/$(whoami)/sample-$i.fa; done > sample-03.txt |
| 22 | ~$ for ((i=60;i<80;i++)); do echo /user/$(whoami)/sample-$i.fa; done > sample-04.txt |
| 23 | ~$ for ((i=80;i<100;i++)); do echo /user/$(whoami)/sample-$i.fa; done > sample-05.txt |
| 40 | id="h998" |
| 41 | mkdir -p /tmp/$id |
| 42 | host=`hostname` |
| 43 | pwd=`pwd` |
| 44 | uid=`whoami` |
| 45 | |
| 46 | while read line; do |
| 47 | input=$line |
| 48 | filename=`basename $input` |
| 49 | echo "$uid@$host:$pwd> hadoop fs -get $input /tmp/$id/$filename" |
| 50 | echo "$uid@$host:$pwd> velveth output-$filename 17 -fasta -short /tmp/$id/$filename" |
| 51 | echo "$uid@$host:$pwd> hadoop fs -put output-$filename ." |
| 52 | done |
| 53 | rm -rf /tmp/$id |
| 54 | }}} |
| 55 | * 接著,讓我們在本地端先驗證一下 testmapper.sh 的運作 |
| 56 | {{{ |
| 57 | ~$ head -n 10 sample-01.txt > sample-00.txt |
| 58 | ~$ cat > testmapper.sh << EOF |
| 59 | #!/bin/bash |
| 60 | |
| 61 | id="h998" |
| 62 | mkdir -p /tmp/\$id |
| 63 | host=\`hostname\` |
| 64 | pwd=\`pwd\` |
| 65 | uid=\`whoami\` |
| 66 | |
| 67 | while read line; do |
| 68 | input=\$line |
| 69 | filename=\`basename \$input\` |
| 70 | echo "\$uid@$host:\$pwd> hadoop fs -get \$input /tmp/\$id/\$filename" |
| 71 | echo "\$uid@$host:\$pwd> velveth output-\$filename 17 -fasta -short /tmp/\$id/\$filename" |
| 72 | echo "\$uid@$host:\$pwd> hadoop fs -put output-\$filename ." |
| 73 | done |
| 74 | rm -rf /tmp/\$id |
| 75 | EOF |
| 76 | ~$ chmod a+x testmapper.sh |
| 77 | ~$ cat sample-00.txt | ./testmapper.sh |
| 78 | h998@hadoop:/home/h998> hadoop fs -get /user/h998/sample-1.fa /tmp/h998/sample-1.fa |
| 79 | h998@hadoop:/home/h998> velveth output-sample-1.fa 17 -fasta -short /tmp/h998/sample-1.fa |
| 80 | h998@hadoop:/home/h998> hadoop fs -put output-sample-1.fa . |
| 81 | h998@hadoop:/home/h998> hadoop fs -get /user/h998/sample-2.fa /tmp/h998/sample-2.fa |
| 82 | }}} |
| 83 | * 讓我們用 Hadoop Streaming 的方式來執行 testmapper.sh |
| 84 | {{{ |
| 85 | ~$ hadoop jar hadoop-streaming.jar -input lab9_input -output lab9_out1 -mapper testmapper.sh -file testmapper.sh |
| 86 | }}} |
| 87 | * 觀察 lab9_out1 的結果,看與本機執行有何不同呢? |
| 88 | {{{ |
| 89 | ~$ hadoop fs -cat /user/$(whoami)/lab9_out1/part-00000 | head |
| 90 | hadoop@hadoop104:/var/lib/hadoop/cache/hadoop/mapred/local/taskTracker/jobcache/job_201106041247_1820/attempt_201106041247_1820_m_000002_0/work> hadoop fs -get /user/h998/sample-60.fa /tmp/h998/sample-60.fa |
| 91 | hadoop@hadoop104:/var/lib/hadoop/cache/hadoop/mapred/local/taskTracker/jobcache/job_201106041247_1820/attempt_201106041247_1820_m_000002_0/work> hadoop fs -get /user/h998/sample-61.fa /tmp/h998/sample-61.fa |
| 92 | hadoop@hadoop104:/var/lib/hadoop/cache/hadoop/mapred/local/taskTracker/jobcache/job_201106041247_1820/attempt_201106041247_1820_m_000002_0/work> hadoop fs -get /user/h998/sample-62.fa /tmp/h998/sample-62.fa |