A laptop-style VM is often off at night, so the daily cleanup job never runs. How do you make sure it runs once a day anyway?
BeginnerScenarioScheduling, automation and scripting
Answer
Situation read → Machines that aren't always on need catch-up scheduling.
What I'd do →
- Put the script in
/etc/cron.daily/, which anacron runs once a day when the machine is up. - Or use a systemd timer with
OnCalendar=dailyandPersistent=true.
Why → Plain cron only runs at the exact minute; if the host is off, the run is skipped.
Interview tip → /var/spool/anacron/ holds the last-run timestamps.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner