Why Cron Scripts Fail: The PATH Environment Variable Issue
A system administrator writes a script that extracts data from a CSV file and inserts it into a database. The script works correctly when run manually but fails when executed by cron. Which environment variable is most likely causing the issue?
Quick Answer
The answer is the PATH environment variable. When a script runs manually, your interactive shell provides a fully populated PATH that includes directories like /usr/local/bin and any custom script locations, but cron executes with a severely restricted default PATH—typically just /usr/bin:/bin. If your script calls commands such as mysql, psql, or a custom utility stored outside these two directories, cron will fail with a “command not found” error. On the LPIC-1 exam, this question tests your understanding of the cron environment’s stripped-down nature versus a user’s login shell; it’s a classic trap where candidates assume the script works everywhere because it works in the terminal. The fix is to set the full PATH explicitly inside the script or in the crontab file itself. Memory tip: “Cron cuts corners—PATH is the first place it cuts.”
⚠ Common exam trap
Watch out — candidates often assume the script's failure is due to a missing HOME or SHELL variable, but the most frequent cron-related issue is the restricted PATH environment, which prevents the script from locating executables.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
PATH
When a script runs manually, the user's interactive shell inherits a fully populated PATH environment variable that includes directories like /usr/local/bin, /usr/bin, and possibly custom script directories. Cron jobs, however, execute with a minimal environment, and the default PATH for cron is often just /usr/bin:/bin. If the script relies on commands (e.g., mysql, psql, or custom scripts) located outside these directories, cron will fail with a 'command not found' error. Setting the full PATH explicitly inside the script or in the crontab file resolves the issue.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
SHELL
Why it's wrong here
SHELL is set by cron to /bin/sh or the user's shell.
- ✗
LANG
Why it's wrong here
LANG affects locale but not command availability.
- ✗
HOME
Why it's wrong here
HOME is set by cron to the user's home directory.
- ✓
PATH
Why this is correct
PATH is often not set in cron, causing command not found errors.
Visual reference
Go deeper
Related to this question
About these practice questions
One of 527 original LPIC-1 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
2 more ways this is tested on LPIC-1
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A cron job is configured to run a script every day at 2:30 AM. The sysadmin notices the job runs but produces no output. Which is the most likely reason?
easy- A.The cron daemon is not running.
- B.The script requires a terminal to run.
- ✓ C.The MAILTO environment variable is not set, and the output is not redirected.
- D.Cron automatically suppresses all output.
Why C: Cron jobs run in a non-interactive, non-terminal environment. By default, cron captures any output (stdout/stderr) from the job and attempts to email it to the user. If the MAILTO variable is not set and the output is not redirected to a file or /dev/null, the output is simply discarded, resulting in no visible output. The job still runs successfully, but the output is lost.
Variation 2. Refer to the exhibit. Why does the cron job fail?
hard- A.The cron job lacks the PATH environment variable.
- B.The script is owned by root, but the cron job runs as a different user.
- ✓ C.The script is not executable.
- D.The script lacks a shebang line.
Why C: C is correct because cron jobs require the script to be executable (i.e., have the execute permission bit set). If the script is not executable, cron will fail to run it even if the shebang line and PATH are correct. The error typically appears in the cron log or as a silent failure.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.