This package helps you to manage and modify your native *nix crontabs.
See also mintware-de/native-cron-bundle if you're looking for a Symfony bundle.
- View / add / edit / delete system cron jobs
- View / add / edit / delete drop in cron jobs
- View / add / edit / delete user cron jobs
- Fully tested (except the adapter for native file system functions)
- Flexible / you can easily replace any important part of the package
composer require mintware-de/native-cron<?phpdeclare(strict_types=1);
useMintwareDe\NativeCron\Content\BlankLine;
useMintwareDe\NativeCron\Content\CommentLine;
useMintwareDe\NativeCron\Content\CronJobLine;
useMintwareDe\NativeCron\CrontabManager;
useMintwareDe\NativeCron\Filesystem\DarwinCrontabFileLocator;
useMintwareDe\NativeCron\Filesystem\FileHandler;
require_once__DIR__.'/vendor/autoload.php';
// Create a new crontab manager$manager = newCrontabManager(
// with a file locator for macOS; Use DebianCrontabFileLocator for debian based distrosnewDarwinCrontabFileLocator(),
// and a default file handlernewFileHandler(),
);
// Read the crontab for the user max$crontab = $manager->readUserCrontab('max');
// Display the current content of the crontabecho$crontab->build();
$crontab// Add a new cronjob
->add(newCronJobLine('* * * * * echo "Hello World" >> /tmp/mylog'))
// Remove all comments and blank lines
->removeWhere(fn ($line) => $lineinstanceof CommentLine || $lineinstanceof BlankLine);
// Display the new content of the crontabecho$crontab->build();
// Write the crontab for the user max// Keep in mind that reading or writing crontab files may require higher user privileges.$manager->writeUserCrontab($crontab, 'max');| Feature | Linux | macOS | Win |
|---|---|---|---|
| System Cron jobs | Yes | Yes | No |
| User Cron jobs | Yes | Yes | No |
| Drop-In Cron jobs | Yes | No | No |
At the moment are Debian based distros and macOS supported. If you need to add support for a different platform, take a look at the CrontabFileLocatorInterface and implement it for your platform.