Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3166  / 2 Years ago, fri, july 8, 2022, 4:42:16

we are trying to set up cron for magento site running in ubuntu server



we are trying following command :



*/5 * * * * php -f /var/www/html/sitename/cron.php


but we are getting error as below :



-bash: */5: No such file or directory


Update 1



enter image description here



Update 2 - Error



PHP Warning:  require(app/bootstrap.php): failed to open stream: No such file or directory in /var/www/html/sitename/cron.php on line 30

PHP Fatal error: require(): Failed opening required 'app/bootstrap.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/sitename/cron.php on line 30


cron.php



<?php


// Change current directory to the directory of current script
chdir(dirname(__FILE__));

require 'app/bootstrap.php';
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')->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;
$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 > /dev/null 2>&1 &");
shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &");
exit;
}
}

Mage::getConfig()->init()->loadEventObservers('crontab');
Mage::app()->addEventArea('crontab');
if ($isShellDisabled) {
Mage::dispatchEvent('always');
Mage::dispatchEvent('default');
} else {
Mage::dispatchEvent($cronMode);
}
} catch (Exception $e) {
Mage::printException($e);
exit(1);
}

More From » cron

 Answers
1

About cron



Quoting wikipedia here




The software utility Cron is a time-based job scheduler in Unix-like
computer operating systems. People who set up and maintain software
environments use cron to schedule jobs (commands or shell scripts) to
run periodically at fixed times, dates, or intervals. It typically
automates system maintenance or administration..




Please check this link for more informations about cron



View crontab



To output/view the crontab of the current user



crontab -l


To view the crontab of another user you would need sudo permissions



sudo crontab -l -u nameOfOtherUser


Edit crontab



To edit your users crontab



crontab -e


or for another user via



sudo crontab -e -u nameOfOtherUser


How your cron could look like



The possible cron line using full path to php



*/5 * * * * /usr/bin/php  -q /var/www/html/sitename/cron.php


or for debugging purposes as mentioned by @Brian



*/5 * * * * /usr/bin/php  -q /var/www/html/sitename/cron.php > /var/www/html/sitename/cron-temp.log 2>&1


This writes a log file called cron-temp.log in /var/www/html/sitename/



Regarding parameters



-q = quiet mode



Your todo




  • Edit your cron and add the new line which defines how often which script should be called

  • Wait until the interval triggers and check the log file if you are using this option


[#15329] Saturday, July 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
utschang

Total Points: 357
Total Questions: 120
Total Answers: 119

Location: Croatia
Member since Sat, May 2, 2020
4 Years ago
;