Show next cron run time

This commit is contained in:
Jamie Cameron
2018-12-16 22:13:14 -08:00
parent 480876fe32
commit bb6aa0e6cc
42 changed files with 166 additions and 0 deletions

View File

@@ -43,3 +43,5 @@ Fixed a security hole what could be exploited by passing in an invalid username.
Added buttons to move cron jobs to the top and bottom of the list.
---- Changes since 1.830 ----
Added a page for manually editing cron jobs.
---- Changes since 1.900 ----
The next run time of each cron job can be displayed by enable a new config option.

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -20,3 +20,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -20,3 +20,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -21,3 +21,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -20,3 +20,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -20,3 +20,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -20,3 +20,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -23,3 +23,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -20,3 +20,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -21,3 +21,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ hourly_only=0
max_jobs=100
vixie_cron=0
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -21,3 +21,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -21,3 +21,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -21,3 +21,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -14,3 +14,4 @@ show_run=0
show_time=1
match_mode=0
match_user=1
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -22,3 +22,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -21,3 +21,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -19,3 +19,4 @@ kill_subs=0
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -11,3 +11,4 @@ single_file=c:/cronw/crontab.txt
show_comment=0
hourly_only=0
max_jobs=100
show_next=0

View File

@@ -4,6 +4,7 @@ max_jobs=Maximum Cron jobs to show,3,Unlimited
show_time=Show job schedules?,1,1-Yes,0-No
show_comment=Show job comments?,1,1-Yes,0-No
show_run=Display running status of jobs?,1,2-Yes, and allow starting and stopping,1-Yes,0-No
show_next=Show next time each job will run?,1,1-Yes,0-No
match_mode=Find job processes by,1,1-Command only,0-Command and arguments
match_user=Match usernames when finding job processes?,1,1-Yes,0-No
kill_subs=Kill sub-processes when terminating jobs?,1,1-Yes,0-No

View File

@@ -1634,5 +1634,114 @@ if ($cmd) {
return &has_command("crontab");
}
=head2 next_run(&job)
Given a cron job, returns the unix time on which it will run next.
=cut
sub next_run
{
my ($job) = @_;
my $now = time();
my @tm = localtime($now);
if ($job->{'special'} eq 'hourly') {
$job = { 'mins' => 0,
'hours' => '*',
'days' => '*',
'months' => '*',
'weekdays' => '*' };
}
elsif ($job->{'special'} eq 'daily') {
$job = { 'mins' => 0,
'hours' => 0,
'days' => '*',
'months' => '*',
'weekdays' => '*' };
}
elsif ($job->{'special'} eq 'weekly') {
$job = { 'mins' => 0,
'hours' => 0,
'days' => '*',
'months' => '*',
'weekdays' => 0 };
}
elsif ($job->{'special'} eq 'yearly') {
$job = { 'mins' => 0,
'hours' => 0,
'days' => 1,
'months' => 1,
'weekdays' => '*' };
}
my @mins = &cron_all_ranges($job->{'mins'}, 0, 59);
my @hours = &cron_all_ranges($job->{'hours'}, 0, 23);
my @days = &cron_all_ranges($job->{'days'}, 1, 31);
my @months = &cron_all_ranges($job->{'months'}, 1, 12);
my @weekdays = &cron_all_ranges($job->{'weekdays'}, 0, 6);
my ($min, $hour, $day, $month, $year);
my @possible;
foreach $min (@mins) {
foreach $hour (@hours) {
foreach $day (@days) {
foreach $month (@months) {
foreach $year ($tm[5] .. $tm[5]+7) {
my $tt;
eval { $tt = timelocal(0, $min, $hour, $day, $month-1, $year) };
next if ($tt < $now);
my @ttm = localtime($tt);
next if (&indexof($ttm[6], @weekdays) < 0);
push(@possible, $tt);
last;
}
}
}
}
}
@possible = sort { $a <=> $b } @possible;
return $possible[0];
}
=head2 cron_range(range, min, max)
=cut
sub cron_range
{
my ($w, $min, $max) = @_;
my $j;
my %inuse;
if ($w eq "*") {
# all values
for($j=$min; $j<=$max; $j++) { $inuse{$j}++; }
}
elsif ($w =~ /^\*\/(\d+)$/) {
# only every Nth
for($j=$min; $j<=$max; $j+=$1) { $inuse{$j}++; }
}
elsif ($w =~ /^(\d+)-(\d+)\/(\d+)$/) {
# only every Nth of some range
for($j=$1; $j<=$2; $j+=$3) { $inuse{int($j)}++; }
}
elsif ($w =~ /^(\d+)-(\d+)$/) {
# all of some range
for($j=$1; $j<=$2; $j++) { $inuse{int($j)}++; }
}
else {
# One value
$inuse{int($w)}++;
}
return sort { $a <=> $b } (keys %inuse);
}
=head2 cron_all_ranges(comma-list, min, max)
=cut
sub cron_all_ranges
{
my @rv;
foreach $r (split(/,/, $_[0])) {
push(@rv, &cron_range($r, $_[1], $_[2]));
}
return sort { $a <=> $b } @rv;
}
1;

View File

@@ -61,6 +61,13 @@ if (&supports_users()) {
print &ui_table_row($text{'edit_active'},
&ui_yesno_radio("active", $job->{'active'} ? 1 : 0));
# Next run time
if (!$in{'new'}) {
$n = &next_run($job);
print &ui_table_row($text{'edit_next'},
$n ? &make_date($n) : "<i>$text{'index_nunknown'}</i>");
}
&convert_comment($job);
$rpd = &is_run_parts($job->{'command'});
if ($rpd) {

View File

@@ -159,6 +159,13 @@ foreach $u (@ulist) {
push(@cols, $job->{'comment'});
}
# Show next run time
if ($config{'show_next'} || $userconfig{'show_next'}) {
my $n = &next_run($job);
push(@cols, $n ? &make_date($n)
: "<i>$text{'index_nunknown'}</i>");
}
# Show running indicator
if ($config{'show_run'}) {
if ($job->{'name'}) {
@@ -252,6 +259,7 @@ elsif (@rows) {
$userconfig{'show_time'} ? ( $text{'index_when'} ) : ( ),
$config{'show_comment'} || $userconfig{'show_comment'} ?
( $text{'index_comment'} ) : ( ),
$config{'show_next'} ? ( $text{'index_next'} ) : ( ),
$config{'show_run'} ? ( $text{'index_run'} ) : ( ),
$access{'move'} ? ( $text{'index_move'}, "" ) : ( ),
], 100, 0, \@tds);

View File

@@ -14,6 +14,8 @@ index_manual=Manually edit cron jobs.
index_return=cron list
index_env=Environment variable
index_move=Move
index_next=Next run
index_nunknown=Unknown
index_run=Running?
index_ecmd=The command $1 for managing user Cron configurations was not found. Maybe Cron is not installed on this system?
index_esingle=The file $1 listing Cron jobs does not exist. Maybe Cron is not installed on this system?
@@ -36,6 +38,7 @@ edit_ecannot=You are not allowed to edit cron jobs for this user
edit_details=Job Details
edit_user=Execute cron job as
edit_active=Active?
edit_next=Next run time
edit_commands=Commands
edit_command=Command
edit_comment=Description