Last active
October 1, 2020 17:14
-
-
Save sherwind/4f4431fdf2098bc4ecccd3567e793d17 to your computer and use it in GitHub Desktop.
Reads and expands a crontab into a 24hour timeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Reads and expands a crontab into a 24hour timeline: | |
# | |
# For each scheduled cron event... | |
# ... outputs the event's time (hh:mm) followed by the event's crontab entry | |
# | |
# This output is sorted into a cron event timeline (however it is still | |
# up to the reader to decode/determine which events run on which days). | |
# | |
# Idea is based on http://staff.washington.edu/corey/tools/crontab-timeline | |
# by Sherwin Daganato, 20201002 | |
perl -alne ' | |
BEGIN { | |
# shamelessly stolen from Set::Crontab | |
sub expand | |
{ | |
my ($spec, $range) = @_; | |
my @list; | |
# 1,2-4,*/3 | |
foreach (split /,/, $spec) { | |
my @pick; | |
my $step = $1 if s#/(\d+)$##; | |
# 0+"01" == 1 | |
if (/^(\d+)$/) { push @pick, 0+$1; } | |
elsif (/^\*$/) { push @pick, @$range; } | |
elsif (/^(\d+)-(\d+)$/) { push @pick, 0+$1..0+$2; } | |
if ($step) { | |
my $i; | |
@pick = grep { defined $_ if $i++ % $step == 0 } @pick; | |
} | |
push @list, @pick; | |
} | |
return \@list; | |
} | |
} | |
next if /^ *(#|$)/; | |
my $minutes = expand($F[0], [0 .. 59]); | |
my $hours = expand($F[1], [0 .. 23]); | |
foreach my $h (@{ $hours }) { | |
foreach my $m (@{ $minutes }) { | |
printf("%02d:%02d\t%s\n", $h, $m, $_) | |
} | |
} | |
' $* | sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment