A job must run on the last day of every month. Cron has no "last day" field. What do you do?
IntermediateScenarioScheduling, automation and scripting
Answer
Situation read → Use a date check or a systemd calendar expression.
What I'd do →
- Cron: run on days 28–31 and check tomorrow's date:
0 23 28-31 * * [ "$(date -d tomorrow +\%d)" = "01" ] && /usr/local/bin/month-end.sh
- systemd timer:
OnCalendar=*-*~01 23:00:00(the~means counting from the end of the month).
Why → % is special in crontab and must be escaped as \%.
Interview tip → The escaped % is a classic "why doesn't my cron work" gotcha.
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?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?BeginnerA one-off data fix must run at 9 PM tonight, just once. How do you schedule it?Beginner