<p><code>activate</code>和<code>deactivate</code>可能是位于<code>$PATH</code>变量中某个条目所指向的脚本。通常,为一个用户本地安装的软件会将语句添加到您的<code>.profile</code>文件或<code>.bashrc</code>中,这些语句扩展了<code>$PATH</code>变量,这样您就可以在不使用完整路径的情况下使用软件的脚本。在</p>
<p>当bash自动加载<code>.profile</code>和{<cd5>}时,CRON不会这样做。至少有两种解决方案。在</p>
<h2>A) 到处都是满路</h2>
<p>要么在CRON作业执行的脚本中使用完整路径,如下所示:</p>
<pre class="lang-sh prettyprint-override"><code>#!/bin/bash
source /path/to/activate manage_oam_users
python $HOME/path/to/script/send.py
source /path/to/deactivate
</code></pre>
<p>也可以使用<code>$HOME</code>代替<code>~</code>。您可以使用shell中的<code>which activate</code>和<code>which deactivate</code>找到完整的路径。在</p>
<h2>B) 源<code>.profile</code>或{<cd5>}</h2>
<p>或者,您可以在CRON选项卡中找到您的<code>.profile</code>(或<code>.bashrc</code>;您必须查看哪个文件用anaconda目录扩展<code>$PATH</code>变量):</p>
^{pr2}$
<h2>额外说明:来源是什么意思?在</h2>
<blockquote>
<p><strong>source</strong> is a Unix command that evaluates the file following the command, as a list of commands, executed in the current context.</p>
</blockquote>
<p>{a1}</p>
<p><code>source</code>命令的常用别名是一个单点(<code>. /path/to/script</code>)。在</p>
<p><a href="https://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables">A related, but more generic question can be found on the UNIX and Linux Stack Exchange.</a></p>