[英]linux cron job isn't running
I have a Ubuntu Server 10. 我有一个Ubuntu Server 10。
At the root cron I have a script to run every day at the same hour. 在root cron,我有一个脚本可以每天在同一时间运行。
Running the script manually it's run fine, but in the cron it doesn't run. 手动运行脚本可以正常运行,但在cron中则无法运行。
At the syslog I got this: 在系统日志中,我得到了:
Aug 23 09:22:01 database CRON[6884]: (root) CMD (./bkp.sh >> /tmp/bkp.log)
Aug 23 09:22:01 database CRON[6883]: (CRON) error (grandchild #6884 failed with exit status 2)
I found the possible source of the problem, I added some LOGs (echo) in the script... 我找到了问题的可能根源,我在脚本中添加了一些日志(回声)...
During script execution, it exits on a "function" definition... 在脚本执行期间,它以“功能”定义退出。
It seems that I have no access to command "function" 看来我无权访问命令“功能”
How can I solve this? 我该如何解决?
Shell scripts launched by cron
must carefully specify the environment that they're running in. Shells run within cron
will be non-interactive, meaning that they will not read /etc/profile
, where $PATH
is typically set. 通过推出Shell脚本
cron
必须认真指定他们在正在运行的环境。中运行壳cron
将非交互式的,这意味着他们将无法读取/etc/profile
,其中$PATH
通常设置。 This means that you will need to specify the paths to all executables called in your script. 这意味着您将需要指定脚本中调用的所有可执行文件的路径。
If you run a lot of cron scripts, it may be worth your time to write a small shell script which will define and export environment variables to be used inside your script, starting with $PATH
. 如果您运行许多cron脚本,则可能值得花时间编写一个小的Shell脚本,该脚本将定义并导出要在脚本中使用的环境变量,以
$PATH
开头。
将脚本放在以下目录中,然后它将每天运行。
/etc/cron.daily/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.