1

Incipit: I have never used sh before.
My server is using linux RedHat and every time I run cron.sh, the server sends me an email with:

shop/cron.sh: line 45: expr: command not found
shop/cron.sh: line 46: ps: command not found

Cron string: /bin/sh /home/mn0198/public_html/shop/cron.sh

I have read that it may be a problem of portability, but I don't even know where I should start.

#!/bin/sh
#
# Magento
#
# NOTICE OF LICENSE
#
# This source file is subject to the Open Software License (OSL 3.0)
# that is bundled with this package in the file LICENSE.txt.
# It is also available through the world-wide-web at this URL:
# http://opensource.org/licenses/osl-3.0.php
# If you did not receive a copy of the license and are unable to
# obtain it through the world-wide-web, please send an email
# to license@magento.com so we can send you a copy immediately.
#
# DISCLAIMER
#
# Do not edit or add to this file if you wish to upgrade Magento to newer
# versions in the future. If you wish to customize Magento for your
# needs please refer to http://www.magento.com for more information.
#
# @category    Mage
# @package     Mage
# @copyright  Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
# @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
#
if [ ! "$1" = "" ] ; then
    CRONSCRIPT=$1
else
    CRONSCRIPT=cron.php
fi

MODE=""
if [ ! "$2" = "" ] ; then
    MODE=" $2"
fi

PHP_BIN=`which php`

# absolute path to magento installation
INSTALLDIR=`echo $0 | sed 's/cron\.sh//g'`

#   prepend the intallation path if not given an absolute path
# the following lines are 45 and 46
if [ "$INSTALLDIR" != "" -a "`expr index $CRONSCRIPT /`" != "1" ];then
    if ! ps auxwww | grep "$INSTALLDIR$CRONSCRIPT$MODE" | grep -v grep 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $INSTALLDIR$CRONSCRIPT$MODE &
    fi
else
    if  ! ps auxwww | grep "$CRONSCRIPT$MODE" | grep -v grep | grep -v cron.sh 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $CRONSCRIPT$MODE &
    fi
fi

EDIT - Command test

I have run these through putty ssh(I don't know if it's correct):

command -v expr >/dev/null 2>&1 || { echo >&2 "not installed.";}
hash expr >/dev/null 2>&1 || { echo >&2 "not installed.";}
type expr >/dev/null 2>&1 || { echo >&2 "not installed.";}


command -v ps >/dev/null 2>&1 || { echo >&2 "not installed.";}
hash ps >/dev/null 2>&1 || { echo >&2 "not installed.";}
type ps >/dev/null 2>&1 || { echo >&2 "not installed.";}

All of them return not installed

  • What is the hosting operating system? expr and ps are standard linux CLI utilities. computerhope.com/unix/uexpr.htm and computerhope.com/unix/ups.htm – B00MER Nov 8 '15 at 20:17
  • Try with /bin/bash /home/mn0198/public_html/shop/cron.sh – Imaginaerum Nov 8 '15 at 20:35
  • @Imaginaerum Already tried with no success... – Razorphyn Nov 8 '15 at 22:17
  • 1
    @B00MER Well, they answered me that shared hosting plans have a lighter OS which don't include those two commands(???)...so yeah, it's pointless to run the sh if ps is not executed, beside the correct execution of the hearthbeat function of AOE_scheduler module...is it possible to use let instead of expr and pgrep instead of ps? – Razorphyn Nov 9 '15 at 20:59
  • 1
    Use php -f cron.php instead in your cron if your host doesn't support, ps or expr. – B00MER Nov 9 '15 at 21:03
2

Use php -f cron.php instead in your cron if your host doesn't support, ps or expr.

1

Just using php -f cron.php doesn't do what cron.sh does.

cron.sh tries to prevent multiple instances of cron.php while php -f cron.php just starts another cron while the first might still run.

that could lead to dead locks!

Edit: Perhaps that's a work around (Mittwald provides that solution)?! It utilizes a lock file instead:

#!/bin/sh
# Compatible versions: 1.9.2.1, 1.9.2.0, 1.9.1.1, 1.9.1.0, 1.9.0.1, 1.8.1.0, 1.8.0.0
lockfile=/tmp/cron.lock
PHP_BIN=/usr/local/bin/php
ABSOLUTE_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)/$(basename "${BASH_SOURCE[0]}")
INSTALLDIR=${ABSOLUTE_PATH%/*}

function cleanup() {
    for cpid in $(jobs -p); do kill $cpid; done
    rm -f $lockfile
}

trap cleanup 1 2 3 6 9 15

if [ ! -f $lockfile ];then
    echo $$ > $lockfile
else
    exit 0
fi

if [ -n "$1" ] ; then
    CRONSCRIPT=$1
else
    CRONSCRIPT=cron.php
fi

for i in default always; do
        $PHP_BIN $INSTALLDIR/$CRONSCRIPT -m$i 1>/dev/null 2>&1 &
done
wait
rm -f $lockfile

exit 0

Rico

  • 1
    I know, unfortunately the linux comands necessary to accomplish this task aren't supported by my host... – Razorphyn Nov 16 '15 at 23:06
  • I edited my answer with a possible solution – Rico Neitzel Nov 24 '15 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.