Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script lists all Magento cronjobs by this command: # clear && php /shell/cron_lister.php
<?php
require_once __DIR__ . '/../abstract.php';
/**
* @see https://gist.github.com/werdan/5827225
*/
class Mage_Shell_CronLister extends Mage_Shell_Abstract
{
public function run()
{
$cronJobs = Mage::app()->getConfig()->getNode('crontab/jobs');
$outputFormat = "%-60s %-20s %-50s";
$datas = [];
printf($outputFormat . "\n", "Job name", "m h dom mon dow", "Object::Method to execute");
foreach($cronJobs->children() as $key => $job) {
$expr = '';
if (isset($job->schedule)) {
$expr = (string) $job->schedule->cron_expr;
if (empty($expr)) {
$expr = (string) Mage::getStoreConfig($job->schedule->config_path);
}
}
$expr = trim($expr);
$datas[$key] = sprintf($outputFormat, 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();
@jaimestuardo
Copy link

jaimestuardo commented Jul 2, 2021

Is this only for Magento 1? I have Magento 2 and abstract.php file is missing so the script does not work.

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