Interview Prep/Linux/Scheduling, automation and scripting

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.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting