Handle hostnames with upper-case letters
[webmin.git] / cron / range.pl
1 #!/usr/local/bin/perl
2 # Only runs the specified cron job if within the date range
3 # XXX support in usermin
4
5 use Time::Local;
6
7 # Parse args
8 ($start, $end, @cmd) = @ARGV;
9 $start && $end && scalar(@cmd) || die "usage: range.pl dd-mm-yyyy dd-mm-yyyy command ...";
10 $stime = &parse_date($start);
11 $stime || die "Invalid start date $start";
12 $etime = &parse_date($end);
13 $etime || die "Invalid ending date $end";
14
15 # Check time range (inclusive)
16 $now = time();
17 if ($now < $stime || $now >= $etime+24*60*60) {
18         exit(0);
19         }
20
21 # Run the rest
22 exec("/bin/sh", "-c", join(" ", @cmd));
23
24 sub parse_date
25 {
26 ($d, $m, $y) = split(/\-/, $_[0]);
27 $y =~ /^\d+$/ && $m =~ /^\d+$/ && $d =~ /^\d+$/ || return undef;
28 return eval { timelocal(0, 0, 0, $d, $m-1, $y-1900) };
29 }
30