Sub topic 1
Why Scheduled Jobs Fail Without Anyone Noticing
A recurring job runs a command on a schedule. Examples include database backups, log cleanup, report generation, and data synchronization. Scheduling the command is only one part of operating it safely. You must also know whether it started, whether it finished, and whether its result was correct.
Prerequisites
This chapter assumes that you can use the Linux command line, edit files, read logs, and write basic shell commands. You should understand users, file permissions, processes, pipes, and exit codes.
The failure gap
A scheduled job often runs without an interactive terminal. No one watches its output. If the command fails at 02:00, the server may continue running normally. The failure becomes visible only when someone later discovers that a backup is missing or a report is stale.
Several separate events can fail:
- The scheduler may not start the job.
- The command may start with different settings from your interactive shell.
- A command in a pipeline may fail while the final command succeeds.
- Output may go somewhere nobody reads.
- The job may run twice at the same time.
- The machine may be off when the scheduled time arrives.
- The job may run as a user without the required permissions.
- A network or storage operation may hang indefinitely.
Treat each event as something to verify. “The schedule exists” does not prove that the job completed successfully.
#!/usr/bin/env bash
set -euo pipefail
/usr/local/bin/export-data.shThe set command makes many shell errors stop the script. Without such safeguards, a script can continue after a failed command and return a misleading success status.
A useful failure model
Use this sequence when investigating a job:
This model separates “did not run” from “ran and failed.” Those cases require different evidence.
The evidence a job should leave
A reliable job leaves enough evidence to answer these questions:
- When did it start and finish?
- Which user ran it?
- What command and configuration did it use?
- What was its exit status?
- Where did standard output and standard error go?
- What input and output files did it use?
- Was another copy already running?
Record failures in a log or journal. Send an alert when a run fails or does not appear by its expected deadline. A successful exit status is useful, but it does not prove that the produced data is complete. Monitoring should also check freshness, size, or another result-specific condition.
First investigation steps
When a job appears to be missing, check in this order:
- Confirm the schedule is installed in the expected crontab or timer unit.
- Confirm the scheduler itself is enabled and running.
- Check the system clock and time zone.
- Look for the job's start record in scheduler logs.
- Run the command manually as its service user.
- Inspect output, error logs, exit status, and expected result files.
These checks create a chain of evidence instead of relying on an assumption that the scheduler “should have run.”
Exercise
A backup file is missing, but the server has no obvious error. What should you establish first?
Show answer
Establish whether the scheduler started the job, then check the command's exit status, captured output, and expected result.