2010-12-14 79 views

Répondre

1

Vous toutes les 5 Cron minutes entre minuit et 01h00 - non inclus.

+0

merci ... de 00:00 à 01:00 toutes les 5 minutes non? –

4

Ce qui suit exécuter le script /home/user/test.pl toutes les 5 minutes à partir de 0 minutes après l'heure puis 5 minutes après et ainsi de suite.

*/5 * * * * /home/user/test.pl 

# .---------------- minute (0 - 59) 
# | .------------- hour (0 - 23) 
# | | .---------- day of month (1 - 31) 
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 
# | | | | .----- day of week (0 - 6) (Sunday=0 or 7) 
# | | | | | 
# * * * * * command to be executed 

De: http://en.wikipedia.org/wiki/Cron

0

Il existe un site utile au http://cronwtf.github.com/ où vous pouvez coller des lignes cron et il vous donnera une explication en anglais de ce qu'il fera. Le collage de vos lignes donne les résultats suivants:

Exécute /command aux minutes: 00,: 05,: 10,: 15,: 20,: 25,: 30,: 35,: 40,: 45,: 50,: 55, à l'heure 0, tous les jours.

Notez que l'heure 0 est de 12h à 1h du matin.

Il existe également un module perl Schedule::Cron::Events qui fait quelque chose de similaire, ce module est disponible dans Ubuntu 16.04. Espérons qu'il est disponible via d'autres gestionnaires de paquets de distributions.

Pour installer le module sur ubuntu:

$ sudo apt install libschedule-cron-events-perl 

En utilisant ce module dans un script:

#!/usr/bin/perl 

use strict; 
use warnings; 

use Schedule::Cron::Events; 

my $cron_line = shift; 

my $count = 20; 

my $cron = new Schedule::Cron::Events($cron_line, Seconds => time()); 
my ($sec, $min, $hour, $day, $month, $year); 

print "The next $count events for the cron line:\n\n" . $cron_line . "\n\nwill be:\n\n"; 

for (1..$count) { 
    # find the next execution time 
    ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent; 
    printf(
     "Event %02d will start at %02d:%02d:%02d on %d-%02d-%02d\n", 
     $_, 
     $hour, 
     $min, 
     $sec, 
     ($year+1900), 
     ($month+1), 
     $day, 
    ); 
} 

$cron->resetCounter; 
($sec, $min, $hour, $day, $month, $year) = $cron->previousEvent; 
printf(
    "\nThe most recent event started at %02d:%02d:%02d on %d-%02d-%02d\n", 
    $hour, 
    $min, 
    $sec, 
    ($year+1900), 
    ($month+1), 
    $day 
); 

produira la sortie suivante:

./cron-event.pl '*/5 0 * * *' 
The next 10 events for the cron line: 

*/5 0 * * * 

will be: 

Event 01 will start at 00:00:00 on 2017-02-22 
Event 02 will start at 00:05:00 on 2017-02-22 
Event 03 will start at 00:10:00 on 2017-02-22 
Event 04 will start at 00:15:00 on 2017-02-22 
Event 05 will start at 00:20:00 on 2017-02-22 
Event 06 will start at 00:25:00 on 2017-02-22 
Event 07 will start at 00:30:00 on 2017-02-22 
Event 08 will start at 00:35:00 on 2017-02-22 
Event 09 will start at 00:40:00 on 2017-02-22 
Event 10 will start at 00:45:00 on 2017-02-22 
Event 11 will start at 00:50:00 on 2017-02-22 
Event 12 will start at 00:55:00 on 2017-02-22 
Event 13 will start at 00:00:00 on 2017-02-23 
Event 14 will start at 00:05:00 on 2017-02-23 
Event 15 will start at 00:10:00 on 2017-02-23 
Event 16 will start at 00:15:00 on 2017-02-23 
Event 17 will start at 00:20:00 on 2017-02-23 
Event 18 will start at 00:25:00 on 2017-02-23 
Event 19 will start at 00:30:00 on 2017-02-23 
Event 20 will start at 00:35:00 on 2017-02-23 

The most recent event started at 00:55:00 on 2017-02-21