Question

I have a cron job which runs a shell script on Ubuntu linux server LTS 12.0.04 every 2 mintues to build elastic search index, below is the shell script:

#! /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 ;

When this script runs through a cron job it seems to give an output as shown below, which has higher number of "Populating website/documents, 100.0% (30/30), 144 objects/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
-------------------------------------------------------------

When I run the script manually it has a lower number of object counts as shown below:

  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

Can someone suggest why this kind of inconsistent behavior is happening, is there a something that needs to be added to shell script, please advise, thnx.

Was it helpful?

Solution

I was able to solve this by changing the path using cd first "cd /var/www/Symfony" in cron schedule as shown below:

 */2 * * * *  cd /var/www/Symfony && /var/www/Symfony/buildDocovaIndex.sh
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top