1

Is there a way to setup cron (or any other scheduler, like anacron) to run such that it checks immediately after I resume working on my laptop (e.g. after suspension or shutdown) whether it has executed a certain script that was scheduled while my laptop was inactive?

The reason for this is that I frequently do things like suspend my laptop or shut it down and in both cases cron obviously doesn't run. When I then return to normal operation the missed commands aren't executed.


I know there is the tool called anacron for machines that aren't running continuously, which therefore periodically checks whether scheduled scripts were run, but the problem with that is that:

  • there is a time interval between checking whether scripts were run and one of the use cases for me is to change my screen color at a certain time in the evening; after starting my laptop later in the evening I'd only be willing to wait at most half a second (!) until the color change is carried out and I guess a scheduler with a time period of half a second is probably inducing a bit of unnecessary load on my system (if such rapid checks are even possible)
  • for anacron the waiting period is days which rules out any tweaks with anacron :(

Running rtcwake is also not an option: It would be way too cumbersome to pad each script with more code to potentially wake the entire system just to do simple plumbing stuff like to change my screen color.

2
  • The "waiting period" for Anacron is whatever you want it to be. For example, you could run Anacron from Cron every minute if you wanted to, to catch any jobs that haven't run within the last day. But Anacron would not be the scheduler you'd use for scheduling anything that needs to run more than once a day. But what you probably want is something that executes on unsuspend. Then also possibly an ordinary @reboot cron job, or whatever hooks Linux/systemd provides for this (I'm not a Linux person).
    – Kusalananda
    Oct 2, 2022 at 6:04
  • Running on unsuspend/reboot would be exactly what I want. (And yes, the scripts Im interested in should run multiple times per day) Oct 2, 2022 at 8:39

1 Answer 1

0

The answer to your question is yes. The “scheduler” you want is systemd timers. They are very flexible, you just need to research all the options available and configure one or more to meet your needs.

The Arch wiki is a good starting point. https://wiki.archlinux.org/title/Systemd/Timers

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .