title: magento cron schedule not working, no heartbeat
body: <p>I have inherited a magento site and the cron schedule does not work. It was set in magento with */5**** and the same in cpanel. I installed AOE Scheduler and all the emails that had been stuck in the queue came through but now I just get a message "Last heartbeat is older than XX". If I run the scheduled tasks manually the emails come through but I get a "405 Error - Not Allowed" page and I find all my file permissions have been changed to 666 (the number of the beast). I have been setting my file permissions to d - 755 and f - 644 but depending on which forum you read this could be wrong. Please help, I have been on this for days.</p>
  
  <p>This is my cron.php</p>
  
  <pre><code>&lt;?php
  
  // Change current directory to the directory of current script
  chdir(dirname(__FILE__));
  
  require 'app/Mage.php';
  
  if (!Mage::isInstalled()) {
      echo "Application is not installed yet, please complete install wizard first.";
      exit;
  }
  
  // Only for urls
  // Don't remove this
  $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
  $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);
  
  Mage::app('admin')-&gt;setUseSessionInUrl(false);
  
  umask(0);
  
  $disabledFuncs = explode(',', ini_get('disable_functions'));
  $isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
  $isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
  
  try {
      if (stripos(PHP_OS, 'win') === false) {
          $options = getopt('m::');
          if (isset($options['m'])) {
              if ($options['m'] == 'always') {
                  $cronMode = 'always';
              } elseif ($options['m'] == 'default') {
                  $cronMode = 'default';
              } else {
                  Mage::throwException('Unrecognized cron mode was defined');
              }
          } else if (!$isShellDisabled) {
              $fileName = basename(__FILE__);
              $baseDir = dirname(__FILE__);
              shell_exec("/bin/sh $baseDir/cron.sh $fileName -mdefault 1 &gt; /dev/null 2&gt;&amp;1 &amp;");
              shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 &gt; /dev/null 2&gt;&amp;1 &amp;");
              exit;
          }
      }
  
      Mage::getConfig()-&gt;init()-&gt;loadEventObservers('crontab');
      Mage::app()-&gt;addEventArea('crontab');
      if ($isShellDisabled) {
          Mage::dispatchEvent('always');
          Mage::dispatchEvent('default');
      } else {
          Mage::dispatchEvent($cronMode);
      }
  } catch (Exception $e) {
      Mage::printException($e);
      exit(1);
  }
  </code></pre>
  
  <p>This is my cron.sh</p>
  
  <pre><code>#!/bin/sh
  # location of the php binary
  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
  if [ "$INSTALLDIR" != "" -a "`expr index $CRONSCRIPT /`" != "1" ];then
      if ! ps auxwww | grep "$INSTALLDIR$CRONSCRIPT$MODE" | grep -v grep 1&gt;/dev/null 2&gt;/dev/null ; then
          $PHP_BIN $INSTALLDIR$CRONSCRIPT$MODE &amp;
      fi
  else
      if  ! ps auxwww | grep "$CRONSCRIPT$MODE" | grep -v grep | grep -v cron.sh 1&gt;/dev/null 2&gt;/dev/null ; then
          $PHP_BIN $CRONSCRIPT$MODE &amp;
      fi
  fi
  </code></pre>