it depends on how complex you want to end up.

regarding (1) you can restart a failed script by placing it in an infinite loop within a parent shell script if you are sure you debugged it enough so not to end up with an infinite pile of core-dumps. You can also have cron checking on it and respawn it if it disappears from the process list. You can also have cron sending it periodically a signal to dump diagnostics. In any event "perpetual" script or cron, it will have to sleep for a while in a loop. (1) makes it easier to change that sleep interval and also importantly, you can wake it up with a signal in order to respond to emergencies. So "continuously running" has a lot of merrits too. And it can too reschedule its wake up time with a Perl alarm (need example code?).

nit-picking: (3) is best with at.

With (1) you can expand your system to scan a queue of future actions from a database: open curtains at 8, close curtains at 5, water plants, etc. And execute if it's time. Each action is consumed unless it is a recurrent type of action (like the curtains). You can have many types of actions and your script would know how to handle each. The database/queue-of-actions can be updated independently and perhaps remotely or by voice. Also a speech synthesizer can read out the entries to the database of actions-to-do when instructed.

With (1) I would use a cron job to only make sure that the script is alive, or to periodically send it a signal to dump some diagnostics to email them to you. To have the script running even after a reboot, turn it into a service with systemctl - that buys you a free respawning within reason.

For your current spec I would go with (2): script is executed every 5 mins, if sunrise it opens, if sunset (calculate it) it closes. And it short-circuits if time of day is not interesting e.g. midnight. That's 12*24 times a day. Nothing really.

edit: basically you end up with a home-cron hehe


In reply to Re: Continuous or timed? by bliako
in thread Continuous or timed? by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.