Coder Social home page Coder Social logo

cronos's Introduction

Cronos

Easily configure cron through PHP.

If you use Symfony 4/5/6, you could use our cool bundle in order to configure your app jobs through fancy annotations!

Setup and Configuration

Require the library via composer:

composer require mybuilder/cronos

Usage

Build Cron

<?php

require 'vendor/autoload.php';

$cron = new MyBuilder\Cronos\Formatter\Cron;
$cron
    ->header()
        ->setPath('path')
        ->setHome('home')
        ->setMailto('[email protected]')
        ->setShell('shell')
        ->setContentType('text')
        ->setContentTransferEncoding('utf8')
    ->end()
    ->comment('Comment')
    ->job('/bin/bash command --env=dev')
        ->setMinute(1)
        ->setHour(2)
        ->setDayOfMonth(3)
        ->setMonth(4)
        ->setDayOfWeek(5)
        ->setStandardOutFile('log')
        ->appendStandardErrorToFile('error')
    ->end();

echo $cron->format();

That will print

[email protected]
HOME=home
SHELL=shell
LOGNAME=logName
CONTENT_TYPE=text
CONTENT_TRANSFER_ENCODING=utf8

#Comment
1    2    3    4    5    /bin/bash command --env=dev > log 2>> error

Updating Cron

<?php

require 'vendor/autoload.php';

use MyBuilder\Cronos\Formatter\Cron;
use MyBuilder\Cronos\Updater\CronUpdater;

$cron = new Cron;
// $cron configuration...

$cronUpdater = CronUpdater::createDefault();
$cronUpdater->replaceWith($cron);

Troubleshooting

  • The current user must have a existing crontab file to use the updater, use crontab -e to create one.
  • When a cron line is executed it is executed with the user that owns the crontab, but it will not execute any of the users default shell files so all paths etc need to be specified in the command called from the cron line.
  • Your crontab will not be executed if you do not have usable shell in /etc/passwd
  • If your jobs don't seem to be running, check the cron daemon is running, also check your username is in /etc/cron.allow and not in /etc/cron.deny.
  • Environmental substitutions do not work, you cannot use things like $PATH, $HOME, or ~/sbin.
  • You cannot use % in the command, if you need to use it, escape the command in backticks.

Created by MyBuilder - Check out our blog for more insight into this and other open-source projects we release.

cronos's People

Contributors

andrey1s avatar angelsk avatar avant1 avatar chris53897 avatar chris8934 avatar cyexy avatar damirtrputec avatar gavinlove avatar keyvanakbary avatar maxbaldanza avatar rainerkraftmb avatar seferov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cronos's Issues

Possibility to append output of cron jobs

Hello.
I think it would be useful to have an opportunity to redirect command output with appending it to file.

Job line fragment would look like

command >> stdout.log 2>>stderr.log

Seems like this feature can be easily implemented.

example reading existing linux cron

hi there, can you please provide a simple example parsing an existing linux cron file ? something like:

  $parsed_cron = $cron->parse('/var/spool/cron/root');

thanks

You should not allow empty key

I forgot to configure the key (forgot to create the bundle configuration).
This resulted in an empty key and when I ran the replace command of the bundle, every existing section (with other keys) in my crontab were replaced by the cron entries.

I think you should not allow empty key or mayby include the line break in the regex pattern used to find the old section.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.