Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script lists all Magento cronjobs in the following way: # php listAllCrons.php Job name m h dom mon dow Object::Method to execute enterprise_giftcardaccount_generage_codes_pool 30 * * * * enterprise_giftcardaccount/pool::applyCodesGeneration enterprise_logging_rotate_logs 1 2 * * * enterprise_logging/observer::rotateLogs enterprise_page_cac…
<?php
// shell/listAllCron.php
require_once 'abstract.php';
class Mage_Shell_CronLister extends Mage_Shell_Abstract
{
public function run()
{
$cronJobs = Mage::app()->getConfig()->getNode('crontab/jobs');
$outputFormat = "%-60s %-20s %-50s";
printf($outputFormat . "\n", "Job name", "m h dom mon dow", "Object::Method to execute");
$lines = "Job name, m h dom mon dow, Object::Method to execute";
foreach($cronJobs->children() as $key => $job) {
$expr = trim((string) $job->schedule->cron_expr);
$datas[$key] = sprintf($outputFormat, trim($job->getName()), $expr, trim((string) $job->run->model));
$datas_csv[$key] = array(trim($job->getName()), $expr, trim((string) $job->run->model));
}
uksort($datas, array($this, 'compareTimes'));
foreach($datas as $job) {
echo $job . "\n";
}
}
public function compareTimes($time1, $time2)
{
$times1 = explode(' ', $time1);
$times2 = explode(' ', $time2);
if(( ! isset($times1[1])) || ($times1[1] == '*')) return -1;
if(( ! isset($times2[1])) || ($times2[1] == '*')) return 1;
$times1[1] = (int) trim($times1[1]);
$times2[1] = (int) trim($times2[1]);
$times1[0] = (int) trim($times1[0]);
$times2[0] = (int) trim($times2[0]);
if($times1[1] != $times2[1]) {
$res = ($times1[1] - $times2[1]) * 1000;
return $res;
}
return $times1[0] - $times2[0];
}
}
$cronLister = new mage_Shell_CronLister();
$cronLister->run();
@xyn22
Copy link

xyn22 commented Sep 2, 2015

$lines variable is never used

@Nerjuz
Copy link

Nerjuz commented Aug 22, 2016

works perfect. Thanks!

@aloha1003
Copy link

aloha1003 commented May 15, 2017

But how to Run List Cronjob On Magento2 ?

@ManishKumar1998
Copy link

ManishKumar1998 commented Apr 8, 2019

How to use this script?

@Sekiphp
Copy link

Sekiphp commented Jun 12, 2019

How to use this script?

By console command: php /path/to/magento/shell/listAllCron.php

@Sekiphp
Copy link

Sekiphp commented Jun 18, 2019

@jaimestuardo
Copy link

jaimestuardo commented Jul 2, 2021

Is this only for Magento 1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment