The 06:00 report never arrived INC-2331

Open2 versionsLinux · Medium · Fix · about 25 min ·Linux

Lab machine

A private Linux machine with the problem already set up. Sessions last up to 60 minutes.
Lena, depot-6 manager opened INC-2331 at 06:34SEV-4

Every morning at 06:30 the depot-6 manager reads the Docklight delivery summary at stand-up. Today there was nothing to read.

jobs/morning.sh runs at 06:00 from cron and writes reports/morning.txt with yesterday's totals, for example delivered=2 failed=1. It has run every day for a year. Last week someone tidied up the helper scripts.

"Ran it from my terminal, works fine. I can just add the folder to my PATH in .bashrc?" (Teo, in chat)

cron starts jobs with a minimal environment: a short PATH, no login profile, no .bashrc, and the user's home as the working directory. A fix that only works in your shell will fail again at 06:00 tomorrow.

Your task

Reproduce the failure in a minimal environment, then make jobs/morning.sh work there without relying on your shell's settings. Running it twice must still leave exactly one report line.

On the machine

  • cron.log: the 06:00 failure
  • jobs/morning.sh and bin/docklight-report
  • events.tsv, yesterday's parcel events
  • env -i PATH=/usr/bin:/bin bash jobs/morning.sh reproduces what cron does

Timeline

Last TueTeo moves docklight-report into the job's bin/ directory during a cleanup.
06:00cron runs morning.sh: "docklight-report: command not found".
06:30Stand-up without numbers.
06:34INC-2331 opened.

Done when

  1. jobs/morning.sh works in cron's minimal environment and writes the report.
  2. Running it twice still leaves exactly one report line.

Hints

Hint 1

The scheduler did start the job. cron.log says what went wrong in it.

Hint 2

Run the job the way cron does: from another directory, with `env -i PATH=/usr/bin:/bin`, and read stderr.

Hint 3

Compare what the job assumes, a command on PATH or paths relative to where you stand, with what cron gives it.

Hint 4

Resolve every path from the script's own location (or set a controlled PATH inside the job).

Show the solution

Read `cron.log`, then reproduce it: `cd empty-home && env -i PATH=/usr/bin:/bin HOME=$PWD bash ../jobs/morning.sh`. The job either relies on PATH to find `docklight-report`, or uses paths relative to the directory it is started from. Derive every path from the script's own location (`root="$(cd "$(dirname "$0")/.." && pwd)"`) and call `"$root/bin/docklight-report" "$root/events.tsv"`. Run it twice in the minimal environment and confirm one report line, `delivered=2 failed=1`.