[英]crontab is returning error
I'm trying to run some crawler with Linux crontab. 我正在尝试使用Linux crontab运行某些搜寻器。
This should go to the Python environment with 这应该转到Python环境
pyenv shell jake-crawler
Here is my crontab -e
这是我的
crontab -e
*/10 * * * * /home/ammt/apps/crawler/scripts/bat_start.sh
This will run every 10 minutes. 这将每10分钟运行一次。 This command line works fine when I type
我输入时此命令行工作正常
(jake-crawler) [jake@KIBA_OM crawler]$ /home/jake/apps/crawler/scripts/bat_start.sh
[DEBUG|run.py:30] 2017-09-24 19:55:49,980 > BATCH_SN:1, COLL_SN:1, 1955 equal 0908 = False
Inside of bat_start.sh
I have init.sh
which changes the environment to Python. 在
bat_start.sh
我具有init.sh
,它将环境更改为Python。
Here is my init.sh
这是我的
init.sh
#!/usr/bin/env bash
export PATH="${HOME}/.pyenv/scripts:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv shell jake-crawler
This has no problem when I personally run it from command line. 当我亲自从命令行运行它时,这没有问题。 But when cron run it by itself, it cannot find the
pyenv
command. 但是当cron
pyenv
运行它时,它找不到pyenv
命令。
I think that you can specify which user should run that script in cron configuration file. 我认为您可以在cron配置文件中指定哪个用户应运行该脚本。 So, if that script is working with your user, then define it in your cron configuration filr.
因此,如果该脚本正在与您的用户一起使用,请在您的cron配置filr中对其进行定义。
See this answer for example... https://stackoverflow.com/a/8475757/3827004 . 例如,请参阅此答案... https://stackoverflow.com/a/8475757/3827004 。
There are two things that diferentiate when you launch an application from the terminal, and when you do from a crontab file: 从终端启动应用程序和从crontab文件启动应用程序时,有两点不同:
.profile
script from your cron job. .profile
脚本。 /dev/tty
. /dev/tty
。 You will have to be very careful on how redirections are handled, as you have them all directed to your tty when running on an interactive session, but all of them will be redirected possibly to a pipe, when run from cron(8)
. cron(8)
运行时,它们都可能会重定向到管道。 This makes your environment quite different and is normally a source of errors. 这会使您的环境与众不同,并且通常是错误的来源。 Read crontab(1) man page for details.
有关详细信息,请阅读crontab(1)手册页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.