Skip to content

Instantly share code, notes, and snippets.

@dfelton
Created March 13, 2023 16:24
Show Gist options
  • Save dfelton/b30f7595bcb67324849352981b416351 to your computer and use it in GitHub Desktop.
Save dfelton/b30f7595bcb67324849352981b416351 to your computer and use it in GitHub Desktop.
Magento - Output XML configured cron jobs
#!/bin/bash
#
# - Finds all crontab.xml files within a Magento project
# - Collects all group name, job name, and schedules within these files
# - Outputs to screen this information, sorted by group & job name
#
php -r '
$results = [];
$files = explode(PHP_EOL, "'"$(find vendor/*/*/etc app/code/*/*/etc -type f -name crontab.xml)"'");
foreach ($files as $file) {
$xml = simplexml_load_string(file_get_contents($file));
foreach ($xml->group as $group) {
$groupName = (string) $group->attributes()->id;
if (!is_array($results[$groupName] ?? null)) {
$results[$groupName] = [];
}
foreach ($group->job as $job) {
$results[$groupName][(string) $job->attributes()->name] = (string) $job->schedule;
}
}
}
ksort($results);
foreach ($results as $groupName => $jobs) {
ksort($jobs);
echo "\nGROUP: $groupName\n";
foreach ($jobs as $jobName => $schedule) {
echo sprintf("\t%s\t%s\n", str_pad($schedule, 16), $jobName);
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment