Sample Header Ad - 728x90

How to run a one-off command at a specified future time in Guix?

0 votes
1 answer
120 views
I want to run a shell command once at a specific time in the future on Guix. My idea was to use the at command, but that seems to not be available on Guix. The imperative nature of my desire goes against the declarative philosophy of Guix somewhat, which I expect is the (indirect) reason at is not available. For example, at requires atrun or atd to be running, which might not fit nicely in the Guix way of doing things. Is there perhaps a Guix-specific way of running a command at a specific time that I have not found yet? For the moment I can just do a sleep xxx; cmd, which should be good enough for now. ---- This is my solution based on @GAD3R suggestion to use mcron, and the [manual on how to emulate at](https://www.gnu.org/software/mcron/manual/mcron.html#AT-commands) ~/.config/hello.guile:
(job '(next-minute-from (current-time) '(25))
     (lambda () (system "echo $(date) >> ~/hello.txt")
                (kill (getppid) SIGINT)))
and then call mcron. This indeed added a line to ~/hello.txt at 25 minutes past the hour. It is a bit more work than using at, but it does work. Two potential improvements I can see: * It seems that job simply expects a function that returns a unix timestamp as first argument. So I suppose it would be feasible to give it the exact timestamp that is necessary. That might also make the killing part redundant. * I suppose that instead of calling mcron manually, it is maybe better to use the [mcron Home Service](https://guix.gnu.org/en/manual/devel/en/html_node/Mcron-Home-Service.html) Finally, maybe it would be worthwhile to explicitly state that mcron replaces also atd or atrun, as those where terms I knew and searched for. For some reason I did not think that cron should also be able to approximate what I looked for. Maybe I'll write a patch.
Asked by BlackShift (313 rep)
Feb 18, 2024, 08:19 PM
Last activity: Feb 19, 2024, 10:51 AM