Cron Jobs: Time Zones, Overlap Control, and Log Rotation

한국어로 읽기

TECH INSIGHT / EXPLAINED

If a report starts every five minutes but takes six minutes, does the next run wait? Ordinary cron does not wait for the earlier process to finish. Define timezone, execution environment, and overlap policy alongside the schedule.

Three people explain overlapping scheduled jobs with a timeline and lock gate.
AI-generated conceptual illustration. Three people explain overlapping scheduled jobs with a timeline and lock gate.

Local execution of the actual project

These captures show the existing project UI or functions executed locally with non-private sample inputs. Each caption states the scope of the execution.

The existing GoClaw scheduler screen running locally with a disabled sample job and the expression 0 9 * * 1-5. API responses are fixtures; no real job was registered or run, and overlap prevention was not tested.
The existing GoClaw scheduler screen running locally with a disabled sample job and the expression 0 9 * * 1-5. API responses are fixtures; no real job was registered or run, and overlap prevention was not tested.

An expression selects clock times

The five user-crontab fields are minute, hour, day of month, month, and weekday. */5 * * * * selects minutes 0, 5, 10 through 55; it does not mean five minutes after the previous run ends. 0 9 * * 1-5 selects weekday 09:00, without knowing exchange holidays.

In Cronie-style implementations, restricting both day fields as 0 9 1 * 1 means the first of the month or Monday. Similar syntax in another scheduler need not have identical semantics. System crontabs also include a username field.

The environment differs from your terminal

PATH, shell, and working directory may differ from an interactive login. Specify executable and configuration paths, verify log-directory permissions, and check that the cron service is installed and running. You can invoke the virtual environment's Python directly instead of activating it.

# User crontab; Cronie-compatible example
CRON_TZ=Asia/Seoul
# Directories must exist and be writable by this user.
*/5 * * * * /usr/bin/flock -n /opt/bot/run/report.lock /opt/bot/.venv/bin/python /opt/bot/report.py >> /opt/bot/log/report.log 2>&1

CRON_TZ sets the schedule timezone only on implementations supporting it. Consult the server's man 5 crontab and verify actual timestamps using a short read-only job. In daylight-saving regions, account for missing or repeated local times.

What flock protects

The lock coordinates cooperating runs on the same server using the same lock file. With -n, contention exits rather than waits, so record skipped runs separately. It does not automatically coordinate another server, a different path, or every network filesystem. Order deduplication still requires persisted identifiers and reconciliation with the venue.

Rotate logs before deleting old files

An actively appended report.log continually receives a new modification time. Deleting files older than 30 days therefore does not bound its size. Set rotation by size or age, a retention count, and disk-usage alerts. Start with a read-only job that records time, output, and exit status; deliberately test overlap and failure.

On Windows, configure Task Scheduler's account, working directory, logon conditions, and already-running policy. Applications needing interactive authentication may not work without a logged-in session. Keep continuous-service restart responsibilities with a service manager rather than repeated cron launches.

References

Content and examples reviewed: 2026-09-29

댓글