0 7 * * * /usr/local/bin/move-curtains open
0 21 * * * /usr/local/bin/move-curtains close
####
0 0 * * * /usr/local/bin/sunrise-sunset
51 6 * * * /usr/local/bin/move-curtains open
13 21 * * * /usr/local/bin/move-curtains close
####
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
sub calc_sunrise_sunset
{
# some astro math here
}
my ($sunrise_hour, $sunrise_minute, $sunset_hour, $sunset_minute) = calc_sunrise_sunset();
open my $pipe,'|-','crontab','-' or die "Can't run crontab: $!";
say $pipe "0 0 * * * $0"; # keep this script running every day at midnight
say $pipe "$sunrise_hour $sunrise_minute * * * /usr/local/bin/move_curtains open"; # open at sunrise
say $pipe "$sunset_hour $sunset_minute * * * /usr/local/bin/move_curtains close"; # close at runset
close $pipe;
####
say $pipe "0 0 * * * $0"; # keep this script running every day at midnight
####
open my $pipe,'|-','crontab','-','-u','root' or die "Can't run crontab: $!";
####
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$year += 1900;
die "Clock lost" if $year < 2020;