Directing output from cron (calls) bash (calls) python3
<p>I have a simple python script, <code>test.py</code>, which prints the date and time and then raises an error.  </p>

<p>I have a bash function defined in <code>.bash_profile</code> and named <code>test()</code>, which calls the script with </p>

<pre><code>$ python3 ~/test.py
</code></pre>

<p>Finally, I have a cron line set to call the <code>test()</code> bash function once a minute for testing with </p>

<pre><code>test &gt;&gt; ~/$(date +\%Y-\%m-\%d_\%H:\%M:\%S).log 2&gt;&amp;1
</code></pre>

<p>When I run the python script or the bash function, I correctly get both the print and the error to the terminal.  When cron calls the python script directory, it logs correctly.  But when cron calls the bash function, nothing is written to the log file.  </p>

<p><strong>Question</strong></p>

<p>How do I correctly direct the output of the python script to the log file when cron calls the bash function?</p>

<p>Why not just put the following line directly in your <code>crontab,</code> and eliminate the <em><code>test()</code> bash function</em> middleman?</p>

<pre><code>* * * * 1    /usr/bin/python3 /home/myname/test.py &gt;&gt; ~/$(date +\%Y-\%m-\%d_\%H:\%M:\%S).log 2&gt;&amp;1
</code></pre>

python bash cron