Interview Prep/Shell Scripting/Troubleshooting: cron and systemd timers

Two schedules misbehave: `*/90 * * * *` runs every hour, not every 90 minutes, and `0 3 1-7 * 1` ("first Monday of the month") runs every Monday and on days 1 to 7.

IntermediateTroubleshootingTroubleshooting: cron and systemd timers
Answer

Likely causes → Steps apply within a field's range: */90 in the minute field (0–59) matches only minute 0, so it fires hourly. And when both day-of-month and day-of-week are restricted, cron runs when either matches (OR, not AND).

Diagnose → Read the schedule as cron does, field by field; for timers, systemd-analyze calendar prints the next real trigger times.

Fix → Express intervals that do not divide an hour in hours or use a timer; do the "first Monday" check in the command:

# every 90 min: two lines
0 0,3,6,9,12,15,18,21 * * *  /opt/job.sh
30 1,4,7,10,13,16,19,22 * * * /opt/job.sh
# first Monday at 03:00
0 3 1-7 * * [ "$(date +\%u)" = 1 ] && /opt/job.sh

With systemd: OnCalendar=Mon *-*-01..07 03:00:00 (systemd ANDs weekday and date) or OnUnitActiveSec=90min.

Prevent → Verify schedules before deploying (systemd-analyze calendar --iterations=5 '...'), and comment every cron line with its intent in plain English.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: cron and systemd timers