Merge branch 'master' into 1786-replace-jekyll-with-zenweb
[arvados.git] / doc / user / tutorials / running-external-program.textile
1 ---
2 layout: default
3 navsection: userguide
4 navmenu: Tutorials
5 title: "Running external programs"
6 navorder: 18
7 ...
8
9 h1. Running external programs
10
11 This tutorial demonstrates how to use Crunch to run an external program by writting a wrapper using the Python SDK.
12
13 *This tutorial assumes that you are "logged into an Arvados VM instance":{{site.basedoc}}/user/getting_started/ssh-access.html#login, and have a "working environment.":{{site.basedoc}}/user/getting_started/check-environment.html*
14
15 In this tutorial, you will use the external program @md5sum@ to compute hashes instead of the built-in Python library used in earlier tutorials.
16
17 Start by entering the @crunch_scripts@ directory of your git repository:
18
19 <notextile>
20 <pre><code>$ <span class="userinput">cd you/crunch_scripts</span>
21 </code></pre>
22 </notextile>
23  
24 Next, using your favorite text editor, create a new file called @run-md5sum.py@ in the @crunch_scripts@ directory.  Add the following code to use the @md5sum@ program to compute the hash of each file in a collection:
25
26 <pre><code class="userinput">{% include run-md5sum.py %}</code></pre>
27
28 Make the file executable:
29
30 notextile. <pre><code>$ <span class="userinput">chmod +x run-md5sum.py</span></code></pre>
31
32 Next, add the file to @git@ staging, commit and push:
33
34 <notextile>
35 <pre><code>$ <span class="userinput">git add run-md5sum.py</span>
36 $ <span class="userinput">git commit -m"run external md5sum program"</span>
37 $ <span class="userinput">git push origin master</span>
38 </code></pre>
39 </notextile>
40
41 You should now be able to run your new script using Crunch, with "script" referring to our new "run-md5sum.py" script.
42
43 <notextile>
44 <pre><code>$ <span class="userinput">cat &gt;the_job &lt;&lt;EOF
45 {
46  "script": "run-md5sum.py",
47  "script_version": "you:master",
48  "script_parameters":
49  {
50   "input": "c1bad4b39ca5a924e481008009d94e32+210"
51  }
52 }
53 EOF</span>
54 $ <span class="userinput">arv -h job create --job "$(cat the_job)"</span>
55 {
56  ...
57  "uuid":"qr1hi-xxxxx-xxxxxxxxxxxxxxx"
58  ...
59 }
60 $ <span class="userinput">arv -h job get --uuid qr1hi-xxxxx-xxxxxxxxxxxxxxx</span>
61 {
62  ...
63  "output":"4d164b1658c261b9afc6b479130016a3+54",
64  ...
65 }
66 </code></pre>
67 </notextile>