-2

I'm looking for a Linux program that can give me an on/off answer based on time. I'm thinking of something that can read simple rules like these

mon-wed 18:30-21:15
thu     17:30-21:15
fri     14:00-17:00
2016.10.10 10:00-13:00

and give me a nonzero exit status when the current time is not in any of the ranges. Is there a program that does this?

Background: I want to keep open an electric door lock during certain times of the day. I started to program the functionality when I thought "somebody must have done this!" I can't seem to find anything though. A library with matching functionality would be welcome too.

sba
  • 99
  • 3
  • 1
    `man 5 crontab` – Ipor Sircer Sep 08 '16 at 14:12
  • Cron is not suitable. I would have to write two rules, one for turning on and one for turning off. Neither Cron nor Anacron have a concept of ranges so they wouldn't know whether they still have to open the door when the device was off. Plus Cron syntax is full of pitfalls, I don't want to write my rules in that syntax. – sba Sep 08 '16 at 14:18
  • crontab runs in every minute. This is enough small interval after power on the device. Crontab has ranges, read the fine manual! – Ipor Sircer Sep 08 '16 at 14:22
  • Assume that `/bin/lock-open` and `/bin/lock-close` exist to operate the lock. Now please try to encode the above rules as crontab entries and I think you will see why I consider Cron unsuitable. I've considered doing it with cron and it is simply too ugly. – sba Sep 08 '16 at 14:32
  • Sorry, your intervals are so ugly. :-> Fork crontab and implement these advanced ranges or get an ups for your linuxbox. – Ipor Sircer Sep 08 '16 at 14:39

1 Answers1

0

Since I couldn't find anything and couldn't get an answer here either, I resigned to write a Python script that understands the format I used in my question.

The script is run from Cron:

* * * * * root /usr/bin/isittime /etc/opening-hours && /sbin/open-lock || /sbin/close-lock
sba
  • 99
  • 3