Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a command or variable works in your terminal but fails in cron, the usual cause is that the scheduled job does not inherit your interactive shell’s full environment. Set the job’s command paths, required variables, and shell assumptions explicitly, then capture its output so you can see what failed.

Why cron cannot see what your terminal can

An interactive login shell may load startup files that define PATH, initialize a language version manager, export application settings, or create aliases. A scheduled cron job runs with an environment supplied by the cron implementation and the job’s owner; it is not necessarily the environment from your terminal.

POSIX specifies a baseline environment that includes HOME, LOGNAME, PATH, and SHELL, but actual behavior can vary by implementation. Its crontab description says the command field is executed by sh at the scheduled time. Cronie, for example, sets SHELL to /bin/sh and sets HOME and LOGNAME from the job owner’s passwd entry; its manual documents implementation-specific overrides and parsing. See the POSIX crontab specification and the Cronie crontab manual.

This explains two common symptoms: command not found usually means the executable is not in the job’s PATH, while an empty application setting usually means the variable was never set or exported for the process that needs it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Diagnose the job in a safe order

  1. Identify the scheduler, table, and owner. Confirm whether the machine uses Cronie, another cron implementation, a container scheduler, or a different scheduler. Check the crontab belonging to the account that runs the job. A personal crontab, /etc/crontab, and files in /etc/cron.d are not interchangeable: system crontab formats commonly include a username field after the schedule, while a user crontab does not. Use the correct syntax for the actual table; Cronie documents its format and options in its manual.
  2. Make failures visible. Temporarily append >> /absolute/path/to/job.log 2>&1 to the command, choosing a log path writable by the job’s account. Alternatively, configure mail or syslog output if those are available and monitored. Cronie documents mail delivery for job output and a daemon option for directing output to syslog in its cron manual. Logs can contain sensitive data, so restrict access and avoid dumping credentials.
  3. Find the executable’s real path. In the terminal where the command works, run command -v tool, replacing tool with the executable name. Use the resulting absolute path in the cron command, then verify that the cron account can execute the file and traverse its parent directories. If software is installed outside standard directories, add its location deliberately to the job’s PATH.
  4. Set an intentional PATH. Cronie accepts environment assignment lines in a crontab. For example, a host might use PATH=/usr/local/bin:/usr/bin:/bin, but check the actual directories and order for the target operating system and account. Do not put user-writable or otherwise untrusted directories in PATH for privileged jobs. An absolute executable path is clearer for a single critical program; an explicit PATH is convenient when a job runs several commands.
  5. Define application variables for the job. For a small number of static values, place assignments above the schedule line, such as APP_ENV=production. To set a value only for one invocation, use APP_ENV=production /absolute/path/to/program. In a wrapper that runs several commands, use export APP_ENV=production so child processes receive the variable. A shell variable that has not been exported is not automatically part of a child process’s environment; see Linux’s process environment documentation.
  6. Make the shell requirement explicit. Cronie runs command fields through /bin/sh by default, or through the shell selected by SHELL. Bash-only syntax such as arrays or certain expansions will not work in a POSIX shell. If the job needs Bash, set SHELL=/bin/bash only after confirming that Bash exists on the host. A wrapper script with a correct shebang is another clear way to select the interpreter.
  7. Check crontab parsing and quoting. In Cronie, environment assignments are standalone active lines. A trailing comment on an assignment becomes part of its value, and comments cannot be appended to a command line. Quote values containing spaces as the shell requires. Cronie also treats an unescaped % in the command field specially: text after it can be sent to the command’s standard input. Consult the Cronie crontab manual when a line parses differently than expected.
  8. Test with a reduced environment. After preserving the intended account, permissions, and working directory, use env -i to run a diagnostic command with only the variables you deliberately provide. This can expose reliance on a shell profile, but it does not reproduce every daemon detail. Compare the diagnostic output from cron with the environment in your terminal, and avoid recording secrets.
  9. Remove temporary diagnostics. Keep only operational logging that is necessary, make log permissions appropriate for the data, and delete any environment dumps that may expose tokens, credentials, or internal paths.

Choose how to provide commands and variables

Approach Best fit Trade-off
Absolute executable path A single important program whose location is known Makes command selection explicit, but every executable needs its own path.
Explicit PATH A job that invokes multiple commands from known directories More concise, but directory order affects which executable runs and unsafe directories can create risk.
Crontab assignments A few static variables needed by one crontab’s jobs Easy to see near the schedule, but offers limited setup and error handling.
Wrapper script Jobs needing several exports, setup commands, a working directory, or explicit error handling More auditable and flexible, but adds a file whose path, permissions, and shebang must be correct.
Cron or a service manager Cron fits straightforward schedules; a service manager may suit tasks needing a managed environment, working directory, restart policy, or service lifecycle. Availability and configuration depend on the host; systemd is not available everywhere.

Example: a user crontab and wrapper

Adapt every path and variable to the target host. This is a user-crontab example; it does not include the username field used by common system crontab formats.

SHELL=/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin
APP_ENV=production

*/5 * * * * /absolute/path/to/job.sh >> /absolute/path/to/job.log 2>&1

If several values or setup steps belong in the wrapper, make them explicit there:

Rank #2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)
#!/bin/sh
export APP_ENV=production
export PATH=/usr/local/bin:/usr/bin:/bin
exec /absolute/path/to/program --option

Confirm that the wrapper is executable by its cron owner and that all referenced paths exist. Paths shown here are examples, not universal defaults.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Version managers, aliases, and missing setup

Tools such as nvm and pyenv, as well as shell aliases, are often initialized in interactive startup files. Cron should not be assumed to read those files. Prefer a stable absolute path to the intended interpreter or executable. If initialization is required, call a deliberate setup script from a wrapper and verify that it works under the job’s shell and account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
ELECROW CrowPi Case Kit for Raspberry Pi 5, 9-Inch Display
  • Not including the Raspberry Pi 5 (8GB), the Crowpi advanced version comes with the Raspberry Pi 5
  • ELECROW Black Case for the Raspberry Pi 5, CrowPi is equipped with a 9-inch HD touchscreen along with a camera; All the regular components used in DIY electronics are packed into the CrowPi development board, such as LCD, LED matrix, buzzer, light sensor, PIR sensor, ultrasonic sensor, IR sensor, etc
  • Raspberry Pi Sensors: The Crowpi raspberry pi 5 programming kit is jam-packed with lots of buttons such as 19 different sensors in a tidy easy to use package; You don't have to wait and wire things
  • Build Quality: Solid ABS shell and well made components in one place make it strong and convenient to travel
  • Programming Lessons: This raspberry pi 5 learning kit ships with step by step instructions and provides 21 lessons to take you through identifying components reading code and running it in the terminal

If the task fundamentally depends on a managed environment, a specific working directory, restart behavior, or service lifecycle, consider whether a service manager available on that host is a better fit than cron. Choose based on the host’s scheduler and operational needs rather than assuming a particular manager is installed.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99
Bestseller No. 4
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
Fully assembled for plug-and-play operation; Includes Raspberry Pi 5 with 8GB RAM; 256 GB PCIe Pi NVMe SSD (Pre-loaded with Pi 64-Bit OS)
$339.97
Best Value
RasTech Raspberry Pi 5 8GB Kit with Active Cooler and Pi5 Case
  • 【What you Get】You will get 1*Pi 5 8GB Single Board,1*RasTech Case,1*Active Cooler,1*Screwdriver,1*Installation instructions,12-month free warranty, lifetime service, 24-hour prompt and friendly response.
  • 【More Connectors】There are two USB 3.0 ports(5Gbps simultaneously) and two USB 2.0 ports, which triple total bandwidth ,support any combination of up to two cameras or displays. Peak SD card performance is doubled through support for the SDR104 high-speed mode. It provides a smooth desktop experience for you. Offer Gigabit Ethernet and a PCIe interface, along with dual-band Wi-Fi and Bluetooth 5.0/BLE wireless capability. The RasTech Pi 5 Kit use the new 27W 5.1V 5A USB-C power connector.
  • 【 Support Dual 4Kp60 Display 】Each of the two microHDMI sockets can control a 4K display at 60 Hertz, now support HDR, offering super HD video for media streaming projects. RPi 5 is the first RPi model that comes with a PCI Express port (PCIe 2.0 x1 with 500 MB/s) to attach SSDs (requires separate M.2 HAT).
  • 【 Excellent Chips And Applications】Pi 5 is a full-size Pi computer using silicon built in-house at Pi. The RP1 “southbridge” provides the bulk of the I/O capabilities for Pi 5. Pi 5 is more friendly and convenient in the development of Internet of Things, Web development, machine identification, automatic control and other electronic equipment applications and network.
  • 【 Faster CPU, Better GPU 】 Pi 5 features a Broadcom BCM2712 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, it delivers a 2–3× increase in CPU performance relative to RaspberryPi 4. The 800MHz VideoCore VII GPU is compatible to OpenGL ES 3.1 and Vulkan 1.2, substantial uplift in graphics performance. Pi 5 Offers lightning-fast CPU speed, a PCI Express interface, a Real Time Clock (RTC) and a power button and runs significantly cooler than Pi 4.
Rank #4
CanaKit Raspberry Pi 5 Desktop PC with SSD (Fully Assembled) (256 GB SSD)
  • Fully assembled for plug-and-play operation
  • Includes Raspberry Pi 5 with 8GB RAM
  • 256 GB PCIe Pi NVMe SSD (Pre-loaded with Pi 64-Bit OS)
  • M.2 HAT+
  • CanaKit Turbine Black Case for the Pi 5

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.