All Projects → TiBeN → Crontabmanager

TiBeN / Crontabmanager

Licence: other
PHP library for GNU/Linux cron jobs management.

Projects that are alternatives of or similar to Crontabmanager

mi-cron
📆 A microscopic parser for standard cron expressions.
Stars: ✭ 16 (-85.84%)
Mutual labels:  cron, crontab, cron-jobs
Chronos
Fault tolerant job scheduler for Mesos which handles dependencies and ISO8601 based schedules
Stars: ✭ 4,303 (+3707.96%)
Mutual labels:  cron, crontab, cron-jobs
Cron Parser
Node.js library for parsing crontab instructions
Stars: ✭ 802 (+609.73%)
Mutual labels:  cron, crontab
Cron Editor
cron editor
Stars: ✭ 22 (-80.53%)
Mutual labels:  cron, crontab
Cronicle
A simple, distributed task scheduler and runner with a web based UI.
Stars: ✭ 979 (+766.37%)
Mutual labels:  cron, crontab
Cronscheduler.aspnetcore
Cron Scheduler for AspNetCore 2.x/3.x or DotNetCore 2.x/3.x Self-hosted
Stars: ✭ 100 (-11.5%)
Mutual labels:  cron, cron-jobs
Cron Utils
Cron utils for parsing, validations and human readable descriptions as well as date/time interoperability.
Stars: ✭ 724 (+540.71%)
Mutual labels:  cron, crontab
Deno cron
A cron Job scheduler for Deno that allows you to write human readable cron syntax with tons of flexibility
Stars: ✭ 35 (-69.03%)
Mutual labels:  cron, crontab
Healthchecks
A cron monitoring tool written in Python & Django
Stars: ✭ 4,297 (+3702.65%)
Mutual labels:  cron, cron-jobs
Tiktok
Python web visualize build on the awesome web framework sanic
Stars: ✭ 55 (-51.33%)
Mutual labels:  cron, cron-jobs
Vue Cron Generator
Cron Generator Implemented by Vue.js and Element-ui(基于Vue&Element-UI构建的在线Cron表达式生成器)
Stars: ✭ 48 (-57.52%)
Mutual labels:  cron, crontab
Go Crond
⏰ Cron daemon written in golang (for eg. usage in docker images)
Stars: ✭ 59 (-47.79%)
Mutual labels:  cron, crontab
Agendash
Agenda Dashboard
Stars: ✭ 620 (+448.67%)
Mutual labels:  cron, crontab
Wecron
✔️ 微信上的定时提醒 - Cron on WeChat
Stars: ✭ 537 (+375.22%)
Mutual labels:  cron, crontab
Dynamic Wallpaper
A simple bash script to set wallpapers according to current time, using cron job scheduler.
Stars: ✭ 762 (+574.34%)
Mutual labels:  cron, crontab
Bree
🚥 The best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support. Works in Node v10+ and browsers, uses workers to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and graceful shutdown. Simple, fast, and lightweight. Made for @ForwardEmail and @ladjs.
Stars: ✭ 933 (+725.66%)
Mutual labels:  cron, crontab
Ppgo job
PPGo_Job是一款可视化的、多人多权限的、一任务多机执行的定时任务管理系统,采用golang开发,安装方便,资源消耗少,支持大并发,可同时管理多台服务器上的定时任务。
Stars: ✭ 1,152 (+919.47%)
Mutual labels:  cron, crontab
Wipe Modules
🗑️ Easily remove the node_modules folder of non-active projects
Stars: ✭ 304 (+169.03%)
Mutual labels:  cron, cron-jobs
Gocron
定时任务管理系统
Stars: ✭ 4,198 (+3615.04%)
Mutual labels:  cron, crontab
Crontab
⏰ Cron expression generator
Stars: ✭ 44 (-61.06%)
Mutual labels:  cron, crontab

CrontabManager

PHP library to manage programmatically GNU/Linux cron jobs.

It enables you to :

  • Deal with your cron jobs in PHP.
  • Create new Cron jobs.
  • Update existing cron jobs.
  • Manage cron jobs of others users than runtime user using some sudo tricks (see below).

Requirements

  • PHP 5.3+
  • crontab command-line utility (should be already installed in your distribution).
  • sudo, if you want to manage crontab of another user than runtime user without running into right issues (see below)

Installation

The library can be installed using Composer.

composer require tiben/crontab-manager ~1.0

Usage

The library is composed of three classes:

  • CrontabJob is an entity class which represents a cron job.
  • CrontabRepository is used to persist/retrieve your cron jobs.
  • CrontabAdapter handles cron jobs persistance in the crontab.

Instantiate the repository

In order to work, the CrontabRepository needs an instance of CrontabAdapter.

$crontabRepository = new CrontabRepository(new CrontabAdapter());

Create new Job and persist it into the crontab

Suppose you want to create a new job which consists of launching the command "df >> /tmp/df.log" every day at 23:30. You can do it in two ways.

  • In Pure oo way :

    $crontabJob = new CrontabJob();
    $crontabJob
        ->setMinutes(30)
        ->setHours(23)
        ->setDayOfMonth('*')
        ->setMonths('*')
        ->setDayOfWeek('*')
        ->setTaskCommandLine('df >> /tmp/df.log')
        ->setComments('Logging disk usage'); // Comments are persisted in the crontab
    
  • From raw cron syntax string using a factory method :

    $crontabJob = CrontabJob::createFromCrontabLine('30 23 * * * df >> /tmp/df.log');
    

You can now add your new cronjob in the crontab repository and persist all changes to the crontab.

$crontabRepository->addJob($crontabJob);
$crontabRepository->persist();

Find a specific cron job from the crontab repository and update it

Suppose we want to modify the hour of an already existing cronjob. Finding existings jobs is done using some regular expressions. The regex is applied to the entire crontab line.

$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$crontabJob = $results[0];
$crontabJob->setHours(21);
$crontabRepository->persist();

Remove a cron job from the crontab

You can remove a job like this :

$results = $crontabRepository->findJobByRegex('/Logging\ disk\ usage/');
$crontabJob = $results[0];
$crontabRepository->removeJob($crontabJob);
$crontabRepository->persist();

Note: Since cron jobs are internally matched by reference, they must be previously obtained from the repository or previously added.

Work with the crontab of another user than runtime user

This feature allows you to manage the crontab of another user than the user who launched the runtime. This can be useful when the runtime user is www-data but the owner of the crontab you want to edit is your own linux user account.

To do this, simply pass the username of the crontab owner as parameter of the CrontabAdapter constructor. Suppose you are www-data and you want to edit the crontab of user bobby:

$crontabAdapter = new CrontabAdapter('bobby');
$crontabRepository = new CrontabRepository($crontabAdapter);

Using this way you will propably run into user rights issues. This can be handled by editing your sudoers file using 'visudo'.
If you want to allow user www-data to edit the crontab of user bobby, add this line:

www-data        ALL=(bobby) NOPASSWD: /usr/bin/crontab

which tells sudo not to ask for password when user www-data calls crontab as user bobby using sudo

Now, you can access to the crontab of user bobby like this :

$crontabAdapter = new CrontabAdapter('bobby', true);
$crontabRepository = new CrontabRepository($crontabAdapter);

Note the second parameter true of the CrontabAdapter constructor call. This boolean tells the CrontabAdapter to use sudo internally when calling crontab.

Enable or disable a cron job

You can enable or disable your cron jobs by using the setEnabled() method of a CronJob object accordingly :

$crontabJob->setEnabled(false);

This will prepend your cron job with a # in your crontab when persisting it.

Unit tests

Tests have been written using PHPUnit and require version 5.3+. To execute tests:

$ phpunit <crontab-library-path>/tests

If you installed the library using Composer and installed dev-dependencies you can execute them using included PHPUnit as dependency:

$ ./vendor/bin/phpunit <crontab-library-path>/tests

Contributions

... are welcome :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].