Pop quiz (because I'm trying to solve this problem):How would you schedule a job to run at sunrise? Or at sunset?The problem, of course, being that "sunrise" and "sunset" are moving targets. Different each day by a few minutes.How would you solve this?#FreeBSD #Linux #cron #popquiz #programming

all 3 comments

sorted by: hot top controversial new old
[–] 1 point 1 week ago

@BastilleBSD since I run a Home Assistant server anyway, I use that to fire off an ssh command using the built-in sunrise/sunset triggers.

  • source
  • [–] 1 point 1 week ago (1 child)

    @BastilleBSD metacpan.org/pod/DateTime::Eve (or similar) and then use that to generate oneshot cronjobs drop-in files w/a prefix of your choosing (for easy cleanup) in /etc/cron.d/, that fire off a command at the precise time per day based on timestamps from this? Cron runs every minute IIRC.Each week, clean up the old oneshot job file and generate next week's job file.Make sure to schedule the cleanup + regeneration task after the last sunset, but also before any summer/normal time changes.

  • source
  • hideshow 1 child comment
  • [–] 1 point 1 week ago

    @ermo @BastilleBSDYou can use the at(1) command to run something once, with no cleanup needed. Run a crontab entry after midnight to schedule two at commands for the day.Install at if it's not there. It's a small package.

  • source
  • parent