精华内容
参与话题
问答
  • Cron

    2018-01-16 17:26:23
    Installation ...Add "liebig/cron": "dev-master" to your /path/to/laravel/composer.json file at the "require": section (Find more about composer at http://getcomposer.org/)Run the compose

    Installation

    Laravel 5

    1. Add "liebig/cron": "dev-master" to your /path/to/laravel/composer.json file at the "require": section (Find more about composer at http://getcomposer.org/)
    2. Run the composer update liebig/cron --no-dev command in your shell from your /path/to/laravel/ directory
    3. Add 'Liebig\Cron\Laravel5ServiceProvider' to your 'providers' array in the /path/to/laravel/config/app.php file
    4. Migrate the database with running the command php artisan migrate --path=vendor/liebig/cron/src/migrations
    5. Publish the configuration file with running the command php artisan vendor:publish - now you find the Cron configuration file at /path/to/laravel/config/liebigCron.php and this file won't be overwritten at any update
    6. Now you can use Cron everywhere for free

    Laravel 4

    1. Add "liebig/cron": "dev-master" to your /path/to/laravel/composer.json file at the "require": section (Find more about composer at http://getcomposer.org/)
    2. Run the composer update liebig/cron --no-dev command in your shell from your /path/to/laravel/ directory
    3. Add 'Liebig\Cron\CronServiceProvider' to your 'providers' array in the /path/to/laravel/app/config/app.php file
    4. Migrate the database with running the command php artisan migrate --package="liebig/cron"
    5. Publish the configuration file with running the command php artisan config:publish liebig/cron - now you find the Cron configuration file at /path/to/laravel/app/config/packages/liebig/cron and this file won't be overwritten at any update
    6. Now you can use Cron everywhere for free

    Configuration

    Cron is designed to work out of the box without the need of configuration. To enable this a few default values are set. To change Cron's default settings there are two possibilities.

    Set methods

    You can use the Cron set methods (e.g. setDatabaseLogging, setRunInterval) to change Cron's behaviour. This changes are temporary and the set methods have to be called every time.

    Config file

    The behaviour values will be loaded from a config file. You can change this values easily by editing in Laravel 5 the /path/to/laravel/app/config/liebigCron.php file and in Laravel 4 the /path/to/laravel/app/config/packages/liebig/cron/config.php file. This is the more permanent way. If you only want to change settings for one run with conditions, we recommend to use the setter methods.

    NOTE: All values set via method will overwrite the values loaded from config file.


    Example

    Cron

    If you use Cron's integrated route or command, you only need to listen for the cron.collectJobs event. The best place to do this is in Laravel 5 the /path/to/laravel5/app/Providers/AppServiceProvider.php file at the boot method and in Laravel 4 the /path/to/laravel/app/start/global.php file.

    Laravel 5 - AppServiceProvider.php

    <?php namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    
    class AppServiceProvider extends ServiceProvider {
    
        //...
    
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot() {
            // Please note the different namespace
            // and please add a \ in front of your classes in the global namespace
            \Event::listen('cron.collectJobs', function() {
    
                \Cron::add('example1', '* * * * *', function() {
                    // Do some crazy things unsuccessfully every minute
                    return 'No';
                });
    
                \Cron::add('example2', '*/2 * * * *', function() {
                    // Do some crazy things successfully every two minute
                    return null;
                });
    
                \Cron::add('disabled job', '0 * * * *', function() {
                    // Do some crazy things successfully every hour
                }, false);
            });
        }
    }

    Laravel 4 - global.php

    Event::listen('cron.collectJobs', function() {
        Cron::add('example1', '* * * * *', function() {
                        // Do some crazy things unsuccessfully every minute
                        return 'No';
                    });
    
        Cron::add('example2', '*/2 * * * *', function() {
            // Do some crazy things successfully every two minute
            return null;
        });
    
        Cron::add('disabled job', '0 * * * *', function() {
            // Do some crazy things successfully every hour
        }, false);
    });

    Inside the anonymous function you can use all the Laravel and Cron functions. In the next step you have to configure the route or command which will start Cron.

    Using Cron's integrated route

    If you don't have shell access to your server, you can easily use an online cronjob service (Google knows some good provider). This provider will run Cron's route in a defined interval. The Cron route has to be protected because if someone else than the service provider invokes it, our jobs will be executed too often. For that reason we need a security key in addition to the route path. This key can be generated with the php artisan cron:keygen command call and has to be set in the Cron config file at the key cronKey.

        // Cron application key for securing the integrated Cron run route - if the value is empty, the route is disabled
        'cronKey' => '1PBgabAXdoLTy3JDyi0xRpTR2qNrkkQy'

    Now you have to configure the address and run interval at your online cronjob service provider. The address for the integrated Cron route is always http://yourdomain.com/cron.php?key=securitykey. For the above example this address could be http://exampledomain.com/cron.php?key=1PBgabAXdoLTy3JDyi0xRpTR2qNrkkQy and the run interval has to be every minute (due to the job with the name "example1"). Now the jobs were added, the route key was generated and the service provider was configured.

    Using Cron's integrated command

    If your hosting provider grants you shell access or you can manage cron jobs with a control panel software (e.g. cPanel or Plesk), the best way to run Cron is to use the integrated artisan cron:run command. For the above example the crontab or control panel software command could be * * * * * /usr/bin/php /var/www/laravel/artisan cron:run.

    NOTE: If you want to use Cron's in time check, which will test if the time between two Cron run method calls are correct, please configure the key runInterval. In our example we call the route every minute so the value should be 1.


    API

    Add a cron job

    Adding a cron job to Cron is very easy by using the static add function. As parameter the name of the cron job, the cron expression and an anonymous function is needed. The boolean isEnabled is optional and can enable or disable this cron job from execution (default is enabled).

    public static function add($name, $expression, $function, $isEnabled = true) {

    The name is needed for identifying a cron job if an error appears and for logging.

    The expression is a string of five or optional six subexpressions that describe details of the schedule. The syntax is based on the Linux cron daemon definition.

        *    *    *    *    *    *
        -    -    -    -    -    -
        |    |    |    |    |    |
        |    |    |    |    |    + year [optional]
        |    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)
        |    |    |    +---------- month (1 - 12)
        |    |    +--------------- day of month (1 - 31)
        |    +-------------------- hour (0 - 23)
        +------------------------- min (0 - 59)
    

    The given anonymous function will be invoked if the expression details match with the current timestamp. This function should return null in the case of success or anything else if there was an error while executing this job. By default, the error case will be logged to the database and to a Monolog logger object (if logger is enabled).

    The isEnabled boolean parameter makes it possible to deactivate a job from execution without removing it completely. Later the job execution can be enabled very easily by giving a true boolean to the method. This parameter is optional and the default value is enabled.

    Example

    \Cron::add('example1', '* * * * *', function() {
                        // Do some crazy things successfully every minute
                        return null;
                    });
    \Cron::add('example2', '*/2 * * * *', function() {
                        // Oh no, this job has errors and runs every two minutes
                        return false;
                    }, true);

    Remove a cron job

    To remove a set cron job on runtime use the remove method with the cron job name as string parameter.

    public static function remove($name) {

    Example

    \Cron::add('example1', '* * * * *', function() {
                        // Do some crazy things successfully every minute
                        return null;
                    });
    \Cron::remove('example1');

    Enable or disable a cron job

    After adding an enabled or disabled cron job ($isEnabled boolean parameter of the add method call) you can disable or enable a cron job by name. For this use the setEnableJob or setDisableJob function.

    public static function setEnableJob($jobname, $enable = true) {
    public static function setDisableJob($jobname) {

    Example

    \Cron::add('example1', '* * * * *', function() {
                        // Do some crazy things successfully every minute
                        return null;
                    });
    \Cron::setDisableJob('example1');
    // No jobs will be called
    $report = \Cron::run();
    \Cron::setEnableJob('example1');
    // One job will be called
    $report = \Cron::run();

    Getter

    To receive the enable status boolean of a job, use the static isJobEnabled($jobname) method.


    Run the cron jobs

    Running the cron jobs is as easy as adding them. Just call the static run method and wait until each added cron job expression is checked. As soon as the time of the expression has come, the corresponding cron job will be invoked. That is the Cron magic. The run method returns a detailed report. By default Cron reckons that you call this method every minute (* * * * *) and by default the report (with their cron jobs errors) will be logged to database. You can change this interval using the setRunInterval function.

    public static function run() {

    Example

    $report = \Cron::run();

    NOTE: The run method call has to be the last function call after adding jobs, setting the interval, deactivating database logging and the other function calls.


    Set the run interval

    The run interval is the time between two cron job route calls. Some cron service provider only supports calls every 15 or even 30 minutes. In this case you have to set this value to 15 or 30. This value is only important to determine if the current run call is in time. If you have disabled database logging in general, you don't have to care about this.

    public static function setRunInterval($minutes) {

    NOTE: If the route call interval is not every minute you have to adjust your cron job expressions to fit to this interval.

    Example

    // Set the run intervall to 15 minutes
    \Cron::setRunInterval(15);
    // Or set the run intervall to 30 minutes
    \Cron::setRunInterval(30);

    Getter

    To recieve the current set run interval use the static getRunInterval() method.


    Enable or disable Laravel logging

    The Laravel logging facilities provide a layer on top of Monolog. By default, Laravel is configured to create daily log files for your application, and these files are stored in app/storage/logs. Cron will use Laravel logging facilities by default. You can disable this by setting the laravelLogging value to false in the config file or by calling the setLaravelLogging function at runtime.

    public static function setLaravelLogging($bool) {

    NOTE: You can add a custom Monolog logger to Cron and enable Laravel logging. In this case all messages will be logged to Laravel and to your custom Monolog logger object.

    Example

    // Laravel logging is enabled by default
    \Cron::run();
    // Disable Laravel logging
    \Cron::setLaravelLogging(false);
    // Laravel logging is disabled
    \Cron::run();

    Getter

    To recieve the enabled or disabled boolean value use the static isLaravelLogging() method.


    Set a Monolog logger

    If you want to add a custom Monolog logger object to Cron use the static setLogger method.

    public static function setLogger(\Monolog\Logger $logger = null) {

    NOTE: If you want to remove the logger, just call the setLogger method without parameters.

    Example

    \Cron::setLogger(new \Monolog\Logger('cronLogger'));
    // And remove the logger again
    \Cron::setLogger();

    Getter

    To recieve the set logger object use the static getLogger() method. If no logger object is set, null will be returned.


    Disable database logging

    By default database logging is enabled and after each cron run a manager object and job objects will be saved to database. We strongly recommend to keep the database logging activated because only with this option Cron can check if the current run is in time. It could make sense in some cases to deactivate the database logging with the setDatabaseLogging method.

    public static function setDatabaseLogging($bool) {

    Example

    \Cron::setDatabaseLogging(false);

    Getter

    To receive the current boolean value of the logging to database variable, just use the static isDatabaseLogging() function.


    Log only error jobs to database

    By default Cron will log all jobs to database. Maybe sometimes you want to log only error jobs (which not return null) to database by using the static setLogOnlyErrorJobsToDatabase function.

    public static function setLogOnlyErrorJobsToDatabase($bool) {

    Example

    // Log only error jobs to database
    \Cron::setLogOnlyErrorJobsToDatabase(true);

    Getter

    To receive the current boolean value of the error job logging, use the static isLogOnlyErrorJobsToDatabase() function.


    Delete old database entries

    Cron can delete old database entries for you. During each run method call, Cron checks if there are old manager and job entries in the database and if the reference value is reached, the entries will be deleted. You can change the reference value by calling the setDeleteDatabaseEntriesAfter function. The default value is 240 hours (10 days). To disable the deletion of old entries just set the reference value to 0.

    public static function setDeleteDatabaseEntriesAfter($hours) {

    Example

    // Set the delete database entries reference value to 10 days (24 hours x 10 days)
    \Cron::setDeleteDatabaseEntriesAfter(240);

    Getter

    To receive the current reference value just use the static getDeleteDatabaseEntriesAfter function.


    Prevent overlapping

    Cron can prevent overlapping. If this is enabled, only one Cron instance can run at the same time. For example if some jobs need 5 minutes for execution but the Cron route will be called every minute, without preventing overlapping two Cron instances will execute jobs at the same time. When running a job twice at the same time, side effects can occur. Cron can avoid such overlaps by using simple locking techniques.

    public static function setEnablePreventOverlapping() {

    Example

    // The configuration could be set via config file with the key 'preventOverlapping' or via method
    \Cron::setEnablePreventOverlapping();
    // Now the Cron run will only run once at the same time
    
    \Cron::setDisablePreventOverlapping();
    // Prevent overlapping is disabled and many Cron run executions are possible at the same time

    Getter

    To receive the current boolean value just use the static isPreventOverlapping function.

    NOTE: To use the overlapping function, Cron needs writing access to the Laravel storage directory. On some Windows machines the lock file cannot be deleted. If you see a delete error message in your log, please disable this feature.


    Events

    Cron supports Laravel events and provides many information about the run status and the job status. With this you can react to errors. Cron supports the following events.

    • cron.collectJobs - fired before run method call to add jobs and to configure Cron. This event is only fired if you use Cron's integrated route or command.
    • cron.beforeRun - fired before run method call to inform that Cron is about to start. Parameter: $runDate.
    • cron.jobError - fired after a job was exectued and this job returned an error (return value is not equal null). Parameter: $name, $return, $runtime, $rundate.
    • cron.jobSuccess - fired after a job was executed and this job did not return an error (return value is equal null). Parameter: $name, $runtime, $rundate.
    • cron.afterRun - fired after the Cron run was finished. Parameter: $rundate, $inTime, $runtime, $errors - number of error jobs, $crons - array of all exectued jobs (with the keys $name, $return, $runtime), $lastRun - array with information of the last Cron run (with the keys $rundate and $runtime). The $lastRun parameter is an empty array, if Cron is called the first time or if database logging is disabled and therefore the $inTime parameter is equals -1.
    • cron.locked - fired if lock file was found. Parameter: $lockfile.

    To subscribe to an event, use Laravels Event facility. The best place for this is the /path/to/laravel/app/start/global.php file.

    \Event::listen('cron.jobError', function($name, $return, $runtime, $rundate){
        \Log::error('Job with the name ' . $name . ' returned an error.');
    });

    Commands

    Cron brings you the following Laravel commands.

    • cron:run - fires the cron.collectJobs event and starts Cron.
    • cron:list - fires the cron.collectJobs event and lists all registered Cron jobs.
    • cron:keygen - generates a security token with 32 characters.

    Reset Cron

    To reset the cron management, call the static reset method. It will reset all variables to the default values.

    public static function reset() {

    Example

    \Cron::add('example1', '* * * * *', function() {
                        // Do some crazy things successfully every minute
                        return null;
                    });
    \Cron::setLogger(new \Monolog\Logger('cronLogger'));
    \Cron::reset();
    // \Cron::remove('example1') === false
    // \Cron::getLogger() === NULL

    Frequently Asked Questions

    Do I really need crontab or an online cronjob service

    Yes, you do. In comparison to a Java application server for example, PHP only runs if it is executed. If crontab or an online cronjob service provider calls PHP and starts the application, Cron can execute the jobs and will start the work. If PHP is not started, the application sleeps and nothing happens.

    What is the best interval to call the route or command?

    The best interval depends on your jobs. If one job should be executed every minute and another every five minutes, the route or command has to be called every minute. In general you have to find the greatest common divisor of your jobs. Please don't forget to change the runInterval config value if the route or command is not called every minute (default value) and if you want to use Cron's in time check.

    Cron is not running properly and returns runtime and inTime with value -1

    By default Cron prevents overlapping. This means that only one Cron instance will run at the same time. If another instance is called, Cron will not run and will return the runtime and inTime parameter with the value -1. On some Windows machines the deletion of the lock file fails and you have to disable this feature. Please have a look at the prevent overlapping section.

    展开全文
  • cron

    2018-06-20 11:39:00
    cron服务每分钟不仅要读一次 /var/spool/cron内的所有文件,还需要读一次/etc/crontab,因此我们配置这个文件也能运用cron服务做一些事情。用 crontab配置是针对某个用户的,而编辑/etc/crontab是针对系统的任务。此...

    1基本概述

    要使用crontab定时器工具,必须要启动crond服务:

    cron服务每分钟不仅要读一次 /var/spool/cron内的所有文件,还需要读一次/etc/crontab,因此我们配置这个文件也能运用cron服务做一些事情。用 crontab配置是针对某个
    用户的,而编辑/etc/crontab是针对系统的任务。此文件的文件格式是: 1、系统执行的工作:系统周期性所要执行的工作,如备份系统数据、清理缓存 2、个人执行的工作:某个用户定期要做的工作,例如每隔10分钟检查邮件服务器是否有新信,这些工作可由每个用户自行设置 crontab是UNIX系统下的定时任务触发器,其使用者的权限记载在下列两个文件中: 文件 含义 /etc/cron.deny 该文件中所列的用户不允许使用crontab命令 /etc/cron.allow 该文件中所列的用户允许使用crontab命令 /var/spool/cron/ 是所有用户的crontab文件

    计划任务,是任务在约定的时间执行已经计划好的。这表面的意思。在Linux中,我们经常用到 crond 服完成这项工作。cron服务器可以根据配置文件约定的时间来执行特定的作务。比如我们可以在配置文件中约定每天上4点,对httpd 服务器重新启动,这就是一个计划任务;

    下面我们先来说说cron;

    cron启动后,它会读取它的所有配置文件(全局性配置文件/etc/crontab,以及每个用户的计划任务配置文件),然后cron会根据命令和执行时间来按时来调用度工作任务。

    systemctl start crond.service  ##启动服务

    systemctl reload crond.service  ##重新载入配置

    你也可以将这个服务在系统启动的时候自动启动:

    在/etc/rc.d/rc.local这个脚本的末尾加上:

    systemctl start crond.service

    2接口举例

    现在Cron这个服务已经在进程里面了,我们就可以用这个服务了,Cron服务提供以下几种接口供大家使用:

    crontab的语法,以备日后救急。先上张超给力的图

    1.直接用crontab命令编辑

    cron服务提供crontab命令来设定cron服务的,以下是这个命令的一些参数与说明:

    crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数

    crontab -l //列出某个用户cron服务的详细内容

    crontab -r //删除某个用户的cron服务

    crontab -e //编辑某个用户的cron服务

    比如说root查看自己的cron设置:crontab -u root -l

    再例如,root想删除fred的cron设置:crontab -u fred -r

    注意crontab是分用户的,以谁登录就会编辑到谁的crontab

    -------------------------------- 如何查看crontab的日志记录 --------------------------------------------------------
    昨天crontab中的同步任务没有执行,不知道是什么原因没有执行,貌似任务hang住了,想查询一下crontab到底问题出在哪里,或者hang在了什么地方。
     
    1. linux
    看 /var/log/cron这个文件就可以,可以用tail -f /var/log/cron观察
     
    2. unix
    在 /var/spool/cron/tmp文件中,有croutXXX001864的tmp文件,tail 这些文件就可以看到正在执行的任务了。
     
    3. mail任务
    在 /var/spool/mail/root 文件中,有crontab执行日志的记录,用tail -f /var/spool/mail/root 即可查看最近的crontab执行情况。
    
    

     

    转载于:https://www.cnblogs.com/mclzy/p/9203007.html

    展开全文
  • cron表达式格式:(cron = "* * * * * *") {秒数} {分钟} {小时} {日期} {月份} {星期} {年份(可为空)} 例 “0 0 12 ? * WED” 在每星期三下午12:00 执行(年份通常 省略) 先了解每个位置代表的含义,在了解每个...

    cron表达式格式:(cron = "* * * * * *")

    {秒数} {分钟} {小时} {日期} {月份} {星期} {年份(可为空)}
    例 “0 0 12 ? * WED” 在每星期三下午12:00 执行(年份通常 省略)
    先了解每个位置代表的含义,在了解每个位置允许的范围,以及一些特殊写法,还有常用的案例,足够你掌握cron表达式

    一、每个字段的允许值
    字段 允许值 允许的特殊字符
    秒 ,0-59 , - * /
    分 ,0-59, - * /
    小时 ,0-23 , - * /
    日期 ,1-31 , - * ? / L W C
    月份 ,1-12 或者 JAN-DEC ,- * /
    星期 ,1-7 或者 SUN-SAT ,- * ? / L C #
    年(可选), 留空, 1970-2099, - * /

    二、允许值的意思
    Seconds (秒) :可以用数字0-59 表示,

    Minutes(分) :可以用数字0-59 表示,

    Hours(时) :可以用数字0-23表示,

    Day-of-Month(天):可以用数字1-31 中的任一一个值,但要注意一些特别的月份

    Month(月) :可以用0-11 或用字符串 “JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC” 表示

    Day-of-Week(每周) :可以用数字1-7表示(1 = 星期日)或用字符口串“SUN, MON, TUE, WED, THU, FRI and SAT”表示

    三、每个符号的意义
    * 表示所有值;
    ? 表示未说明的值,即不关心它为何值;
    - 表示一个指定的范围;
    , 表示附加一个可能值;
    / 符号前表示开始时间,符号后表示每次递增的值;
    L("last") ("last") "L"用在day-of-month字段意思是 “这个月最后一天”;用在 day-of-week字段, 它简单意思是 “7” or “SAT”。 如果在day-of-week字段里和数字联合使用,它的意思就是 “这个月的最后一个星期几” – 例如: “6L” means “这个月的最后一个星期五”. 当我们用“L”时,不指明一个列表值或者范围是很重要的,不然的话,我们会得到一些意想不到的结果。
    W("weekday") 只能用在day-of-month字段。用来描叙最接近指定天的工作日(周一到周五)。例如:在day-of-month字段用“15W”指“最接近这个 月第15天的工作日”,即如果这个月第15天是周六,那么触发器将会在这个月第14天即周五触发;如果这个月第15天是周日,那么触发器将会在这个月第 16天即周一触发;如果这个月第15天是周二,那么就在触发器这天触发。注意一点:这个用法只会在当前月计算值,不会越过当前月。“W”字符仅能在 day-of-month指明一天,不能是一个范围或列表。也可以用“LW”来指定这个月的最后一个工作日。
    # 只能用在day-of-week字段。用来指定这个月的第几个周几。例:在day-of-week字段用"6#3"指这个月第3个周五(6指周五,3指第3个)。如果指定的日期不存在,触发器就不会触发。
    C指和calendar联系后计算过的值。例:在day-of-month 字段用“5C”指在这个月第5天或之后包括calendar的第一天;在day-of-week字段用“1C”指在这周日或之后包括calendar的第一天。

    四、一些cron表达式案例
    */5 * * * * ? 每隔5秒执行一次
    0 */1 * * * ?每隔1分钟执行一次
    0 0 5-15 * * ? 每天5-15点整点触发
    0 0/3 * * * ? 每三分钟触发一次
    0 0-5 14 * * ?在每天下午2点到下午2:05期间的每1分钟触发
    0 0/5 14 * * ? 在每天下午2点到下午2:55期间的每5分钟触发
    0 0/5 14,18 * * ? 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
    0 0/30 9-17 * * ? 朝九晚五工作时间内每半小时
    0 0 10,14,16 * * ? 每天上午10点,下午2点,4点

    0 0 12 ? * WED表示每个星期三中午12点
    0 0 17 ? * TUES,THUR,SAT每周二、四、六下午五点
    0 10,44 14 ? 3 WED每年三月的星期三的下午2:10和2:44触发
    0 15 10 ? * MON-FRI 周一至周五的上午10:15触发
    0 0 23 L * ?每月最后一天23点执行一次
    0 15 10 L * ? 每月最后一日的上午10:15触发
    0 15 10 ? * 6L 每月的最后一个星期五上午10:15触发
    0 15 10 * * ? 2005 2005年的每天上午10:15触发
    0 15 10 ? * 6L 2002-2005 2002年至2005年的每月的最后一个星期五上午10:15触发
    0 15 10 ? * 6#3每月的第三个星期五上午10:15触发

    "30 * * * * ?" 每半分钟触发任务
    "30 10 * * * ?"每小时的10分30秒触发任务
    "30 10 1 * * ?" 每天1点10分30秒触发任务
    "30 10 1 20 * ?" 每月20号1点10分30秒触发任务
    "30 10 1 20 10 ? *" 每年10月20号1点10分30秒触发任务
    "30 10 1 20 10 ? 2011" 2011年10月20号1点10分30秒触发任务
    "30 10 1 ? 10 * 2011" 2011年10月每天1点10分30秒触发任务
    "30 10 1 ? 10 SUN 2011" 2011年10月每周日1点10分30秒触发任务
    "15,30,45 * * * * ?" 每15秒,30秒,45秒时触发任务
    "15-45 * * * * ?" 15到45秒内,每秒都触发任务
    "15/5 * * * * ?" 每分钟的每15秒开始触发,每隔5秒触发一次
    "15-30/5 * * * * ?" 每分钟的15秒到30秒之间开始触发,每隔5秒触发一次
    "0 0/3 * * * ?" 每小时的第0分0秒开始,每三分钟触发一次
    "0 15 10 ? * MON-FRI" 星期一到星期五的10点15分0秒触发任务
    "0 15 10 L * ?" 每个月最后一天的10点15分0秒触发任务
    "0 15 10 LW * ?" 每个月最后一个工作日的10点15分0秒触发任务
    "0 15 10 ? * 5L" 每个月最后一个星期四的10点15分0秒触发任务
    "0 15 10 ? * 5#3" 每个月第三周的星期四的10点15分0秒触发任务

    五、表达式生成器

    http://cron.qqe2.com/

    声明:本文转载自 https://blog.csdn.net/weixin_40426638/article/details/78959972

    展开全文
  • <p>when i use laravel cron api "liebig/cron" <pre><code>Route::get('/cron/run/c68pd2s4e363221a3064e8807rrt342', function () { Cron::add('example1', '* * * * *', function() { $test = new Test(); ...
  • SpringQuartz定时任务的cron表达式书写

    万次阅读 2018-09-17 15:09:28
    SpringQuartz定时任务的使用,要配置这个定时任务什么时候执行,周期是多少,周期内执行多少次,这个都是cron表达式来控制的,下面详解一下这个cron表达式。 一、先来举些例子 【1】0 0 10,14,16 * * ? 每天上午10...

    分享一个人工智能教程,零基础入门!http://www.captainbed.net/inner

    SpringQuartz定时任务的使用,要配置这个定时任务什么时候执行,周期是多少,周期内执行多少次,这个都是cron表达式来控制的,下面详解一下这个cron表达式。

    一、先来举些例子

    【1】0 0 10,14,16  *  *  ? 每天上午10点,下午2点,4点
    【2】0 0/30 9-17 * * ? 朝九晚五工作时间内每半小时
    【3】0 0 12 ? * WED  表示每个星期三中午12点
    【4】0 0 12 * * ? 每天12点触发 
    【5】0 15 10 ? * * 每天10点15分触发 
    【6】0 15 10 * * ? 每天10点15分触发 
    【7】0 15 10 * * ? * 每天10点15分触发 
    【8】0 15 10 * * ? 2005 2005年每天10点15分触发 
    【9】0 * 14 * * ? 每天下午的 2点到2点59分每分触发 
    【10】0 0/5 14 * * ? 每天下午的 2点到2点59分(整点开始,每隔5分触发) 
    【11】0 0/5 14,18 * * ? 每天下午的 2点到2点59分、18点到18点59分(整点开始,每隔5分触发) 
    【12】0 0-5 14 * * ? 每天下午的 2点到2点05分每分触发 
    【13】0 10,44 14 ? 3 WED 3月每周三下午的 2点10分和2点44分触发 
    【14】0 15 10 ? * MON-FRI 从周一到周五每天上午的10点15分触发 
    【15】0 15 10 15 * ? 每月15号上午10点15分触发 
    【16】0 15 10 L * ? 每月最后一天的10点15分触发 
    【17】0 15 10 ? * 6L 每月最后一周的星期五的10点15分触发 
    【18】0 15 10 ? * 6L 2002-2005 从2002年到2005年每月最后一周的星期五的10点15分触发 
    【19】0 15 10 ? * 6#3 每月的第三周的星期五开始触发 
    【20】0 0 12 1/5 * ? 每月的第一个中午开始每隔5天触发一次 
    【21】0 11 11 11 11 ? 每年的11月11号 11点11分触发(光棍节)

    二、cron表达式格式

    corn表达式格式为七个域,如:
    秒 分 时 日 月 周 年
    每一个域之间空格隔开,不指定“年”域时,年域可省略不写,如:
    秒 分 时 日 月 周

    三、cron表达式七个域列表

    ####注意####:需要注意的是“周”域中,使用数值表示时,7表示周六,1表示周日 

    四、符号使用说明

    1、所有域均可用“,”,“-”,“*”,“/”
    【1】,    x,y表示x和y
    【2】-    x-y表示x到y
    【3】   表示每TIME
    【4】/    x/y表示从x起,每隔y

    2、“日”域另有“?”,“L”,“W”,“C”
    【1】?    表示不指定“日”域的值。规则是指定“周”域,则“日”域必须为“?”。反之,指定“日”域,则“周”域必须为“?”。如0 0 12 ? * MON 或 0 0 12 1 * ?
    【2】L    2种写法。一,表示月末几天,如2L, 表示月末的2天。二,表示月末倒数第几天,如L-3,表示月末倒数第3天。
    【3】   表示临近某日的工作日,如15W,表示最接近15号的工作日,可能是15号(刚好是工作日)、15号前(刚好周六)或15号后(刚好周日)。
    【4】   表示和Calendar计划关联的值,如1C表示,1日或1日后包括Carlendar的第一天。
    【5】LW    L和W的组合,只能出现在"日"域中。表示某月最后一个工作日,不一定是周五(详细见结尾PS)。

    3、“周”域另有“?”,“L”,“#”,“C”
    【1】?    表示不指定“周”域。规则是指定“日”域值,则“周”域值必须为“?”。反之,指定“周”域值,则“日”域值必须为“?”。如0 0 12 1 * ? 或 0 0 12 ? * MON
    【2】L    表示某月的最后一个周几,如1L, 表示某月的最后一个周日(1表示周日),7L,表示某月的最后一个周六(7表示周六)。
    【3】   只能出现在"周"域中,表示第几个周几,x#y,y表示第几个,x表示周的值,如6#2,表示第2个周五(6表示周五)。
    【4】C    表示和Calendar计划关联的值,如1C表示,周日或周日后包括Carlendar的第一天。

    ####注意####
    “日域”域中,L和W组合为“LW”时,网上有很多种定义,比如:
    说法一:LW表示某月的最后一个工作日
    说法二:LW某月最后一周的最后一个工作日,即周五 

    五、附上cron表达式生成工具

    1、cron表达式在线生成工具http://www.pppet.net/

     

     

    展开全文
  • <div><p>I just realized that <a href="https://github.com/adamchainz/pretty-cron"><code>pretty_cron</code></a> is ;cron&unscoped_q=cron">used in a few places in this project</a> but ...
  • I have the same issue as stated in <a href="https://drupal.stackexchange.com/questions/249377/cron-job-in-custom-module-not-appearing-in-cron-settings-using-elysia-cron?rq=1">...
  • cron 表达式0 0/10 * * * 与 0 */10 * * *的区别

    万次阅读 热门讨论 2018-06-08 17:17:36
    前段时间使用cron表达式,发现配置每x分钟执行的时候。第一次执行时间,总是不太对。第二次的执行时间是正确的。 cron 0 */7 * * * # 启动时间 xx:40:00 # 第一次执行时间 xx:42:00 # 第二次执行时间 xx:42:00 ...
  • <p>In hopes that it would not abort the last execution, I tested setting the cron to run every 5 minutes, which works fine, however a conversion of a video may take over 5 minutes so I need to figure ...
  • <p>Everything working well in my YetiForce 5.0.0 complete on Ubuntu but i have problems with CRON. I read a instructions on: <a href="url">...
  • Prop-payout cron

    2020-11-29 07:11:11
    m looking for suggestions as to why the prop payout cron would be hanging, When everything else is working fine, MPOS says the cron is currently active, started, and never finished. I have no console ...
  • <p>When using cron module the job entered into the cron.d file is missing a newline at end of file (cron fails to run the job file is there is no new line at the end of file). <p>Example: <pre><code> ...
  • Magento如何配置cron

    2011-02-23 18:09:04
    <p>i have configured a custom cron in one of my modules, i want it be executed every 1 week, at 11:00 am, i've wrote this in my config.xml <pre><code><cron_expr>0 0 * * 1</cron_expr> ...
  • cron生成表达式Java版

    2019-01-27 16:24:43
    Cron Expressions——Cron 表达式 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天(星期)(1~7 1=SUN 或 SUN,MON,TUE,WED,THU,FRI,...
  • If I have 5 related cron jobs, added seperately admist 100 other unrelated cron jobs, it will get harder to find these cron jobs in the long list of cron jobs. <p>Should I stick to cPanel's GUI? Or ...
  • <p>However the script is not called by the cron job. I have read the Jelastic documentation for cron jobs (<a href="http://docs.jelastic.com/cron-job" rel="nofollow">...
  • cron表达式cron生成器

    2018-12-05 17:45:23
    cron表达式cron生成器
  • <p>Fun thing is, if I enter the docker container and execute the command I use for the cronjob, it works. And <code>...
  • cron安装包

    热门讨论 2016-09-27 09:58:59
    crontab是linux操作系统定时任务执行工具,包含两个安装包 vixie-cron和crontabs
  • cron表达式

    2016-08-20 18:30:05
    cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month DayofWeek Year Seconds Minutes Hours DayofMonth ...

空空如也

1 2 3 4 5 ... 20
收藏数 26,795
精华内容 10,718
关键字:

cron