crontab not fully working. only echo statements being run
<p>I have a job in my crontab to run a script (<code>/home/sys_bio/username/tracer.sh</code>) every minute. The script contains</p>

<pre><code>#!/usr/bin/env bash

echo "starting"
/home/sys_bio/username/p35/bin/python3.5 -m qefunctional.qe.tests.prodprobe -p post -j test.json
echo "finised"
</code></pre>

<p>When I am in the directory <code>/home/sys_bio/username/</code> and I run the commany <code>./tracer.sh</code>, it runs as expected.</p>

<p>However when I add the job to the crontab, only the <code>echo</code> portions run. </p>

<p>Another thing to note is <code>p35</code> is where my python3 is located. So <code>/home/sys_bio/username/p35/bin/python3.5</code> is how I run all my python3 scripts. </p>

<p>This is what I have in my crontab</p>

<p><code>* * * * * /home/sys_bio/username/tracer.sh &gt;&gt; /home/username/tracer.cron.txt</code></p>

<p>I am getting the <code>.txt</code> file created but only the echo statements are being saved.</p>

<p>This may seem confusing but the directory structure is like so:</p>

<pre><code>   /home
      /sys_bio
         /username
            /qefunctional
               __init__.py
               /qe
                  __init__.py
                  /tests
                     __init__.py
                     prodprobe.py
            test.json
            /p35
               /bin
                  python3.5
            tracer.sh
      /username
         tracer.cron.txt
</code></pre>

<p><strong>* edits *</strong></p>

<p>I was able to add a bit more to my script so I can redirect errors to a file. The script now looks like this and I am getting this error:</p>

<pre><code>/home/sys_bio/username/p35/bin/python3.5: Error while finding spec for 'qefunctional.qe.tests.prodprobe' (&lt;class 'ImportError'&gt;: No module named 'qefunctional')
</code></pre>

<p>script:</p>

<pre><code>#!/usr/bin/env bash

echo "Starting Tracer POST"

/home/sys_bio/username/p35/bin/python3.5 -m qefunctional.qe.tests.prodprobe -p post -j /home/sys_bio/username/test.json  -d -v  2&gt;/home/username/crontab.output

echo "Ending Tracer POST"
</code></pre>

<p>Including the path to bash shell might be needed:</p>

<pre><code>* * * * * /bin/sh /home/sys_bio/username/tracer.sh &gt;&gt; ...
</code></pre>

<p><code>cron</code> otherwise might not really know what to do. </p>

<p>The same principle also applies to what is included in your script. Using relative file names can fail since they are often not interpreted the same as if you were using your local interactive shell (eg):</p>

<pre><code>test.json
</code></pre>

<p>It might be necessary to use the absolute paths (eg):</p>

<pre><code>/full/path/to/test.json
</code></pre>

<p><strong>EDIT</strong>: It's apparent from the error generated by Python the issue is definitely path related. Python is trying to locate the module in the path <code>/home/sys_bio/username/p35/bin/python3.5</code> instead of two directories up in <code>/home/sys_bio/username/</code>. The fix would be to <code>cd</code> into the directory or by giving the absolute path to the module. By adding the following into the <code>.sh</code> script:</p>

<pre><code>cd /home/sys_bio/username
</code></pre>

<p>Should allow the command following it to look for the module there instead of two levels down.</p>

python bash cron