我有一个cron作业,每2分钟就在Ubuntu linux服务器LTS 12.0.04上运行一个shell脚本来构建弹性搜索索引,下面是shell脚本:
#! /bin/sh
echo "--------------------------------------------------------------" >> /var/log/syslog ;
echo " CRON Task: DOCOVA Elastic Indexer DV " >> /var/log/syslog ;
echo "--------------------------------------------------------------" >> /var/log/syslog ;
echo "populate index ..." >> /var/log/syslog ;
echo "start time: $(date)" >> /var/log/syslog;
/usr/bin/php /var/www/Symfony/app/console fos:elastica:populate --no-reset -v >> /var/log/syslog;
#php app/console fos:elastica:populate >> /var/log/syslog;
echo "index task completed." >> /var/log/syslog ;
echo "end time: $(date) " >> /var/log/syslog;
echo "-------------------------------------------------------------" >> /var/log/syslog ;
当这个脚本通过cron作业运行时,它似乎给出了如下所示的输出,其中包含更多“填充网站/文档,100.0%(30/30),144个对象/ s”
Feb 28 11:58:01 ubuntu-teitr CRON[5138]: (root) CMD (/var/www/Symfony/buildDocovaIndex.sh)
--------------------------------------------------------------
CRON Task: DOCOVA Elastic Indexer DV
--------------------------------------------------------------
populate index ...
start time: Fri Feb 28 11:58:01 EST 2014
command: php /var/www/Symfony/app/console fos:elastica:populate --env=prod
Populating website/documents, 100.0% (30/30), **144 objects/s**
Refreshing website
index task completed.
end time: Fri Feb 28 11:58:01 EST 2014
-------------------------------------------------------------
当我手动运行脚本时,它具有较少的对象计数,如下所示:
populate index ...
start time: Fri Feb 28 12:09:08 EST 2014
command: php /var/www/Symfony/app/console fos:elastica:populate --env=prod
Populating website/documents, 100.0% (30/30), **12 objects/s**
Refreshing website
index task completed.
end time: Fri Feb 28 12:09:10 EST 2014
有人可以建议为什么会出现这种不一致的行为,是否有需要添加到shell脚本的内容,请告知,thnx。
答案 0 :(得分:0)
我能够通过首先使用cd改变路径来解决这个问题" cd / var / www / Symfony"在cron时间表中如下所示:
*/2 * * * * cd /var/www/Symfony && /var/www/Symfony/buildDocovaIndex.sh