Payments are experiencing issues due to temporary restrictions in Russia. If your payment does not go through, please submit a support request.Our support team is available 24/7 — we are always here to help with hosting and server issues.We are now accepting requests for dedicated server rental and colocation services in our data center.Reminder: we recommend enabling backups for additional data protection.A new VPS/VDS lineup with NVMe storage and improved performance is now available.Maintenance work on some servers has been completed. All services are operating normally.
Article3 min readViews1

Why Cron Does Not Run a Task That Works in the Terminal

Check the user, schedule, and Cron environment without manually re-running a potentially dangerous task or modifying crontab.

A mechanical timer next to the workstation
In this article

The script runs successfully when executed manually but yields no result on schedule. In the terminal, it receives the user's environment, working directory, and interactive settings. Cron operates under different conditions. Diagnosis begins by precisely recording the task and its execution method, not by adding another copy to the schedule.

View the current user's table

The example assumes a standard Cron implementation in Debian or Ubuntu. To view it, use:

crontab -l

The command does not edit anything. A message indicating the absence of a table for the current user does not mean the server has no tasks at all: the task may belong to another account, reside in the system schedule, or be triggered by a systemd timer.

Do not use commands to delete or install a table during initial analysis. It is crucial to first locate the existing entry and avoid duplication, especially if the task sends emails, generates documents, or processes orders.

Check the record format

In a custom table, the command follows the schedule fields. System tables have an additional user field. Moving between these formats without adaptation leads to unexpected interpretation.

Check the minute, hour, day of the month, month, and day of the week. The day of the month and day of the week conditions have specific handling quirks in common cron implementations. If the schedule is complex, verify it against the documentation for the installed version, not based on the visual appearance of the string.

Compare the environment

Verify the full path to the interpreter and program, the variables the script depends on, and the working directory. A command found in an interactive terminal via the user's PATH may be missing in the job environment.

Example: a script opens a file using a relative path. In a manual test, you switched to the project directory beforehand, but cron launches it from a different location. In this situation, the issue is not with the schedule. You must make the working directory or paths explicit in a consistent job configuration.

Find the output and the launch fact

Check where standard output and errors are directed. If they are not saved anywhere and local mail delivery is not configured, an important message may go unnoticed. The presence of a launch entry in the system log confirms the command started, but not that the application succeeded.

In a Debian-based system, the cron service log can be viewed for a short period if it is sent to the journal:

journalctl -u cron.service --since '-1 hour' --no-pager

The service name and logging method depend on the system. Empty output requires checking these conditions, not concluding that the scheduler did nothing.

Do not blindly re-run a task

If the previous instance is still running, a re-run can cause contention or duplication. First, determine whether protection against parallel execution is in place and whether repeating the operation is safe. To verify, you can prepare a separate harmless script in a test environment, but do not use it as a substitute for proof that the production task is working correctly.

Save the user, schedule, program path, environment, and the result of the last run. After a targeted fix, wait for the scheduled execution to occur and verify the final result. A successful manual run is a useful starting point, but only execution under the scheduler confirms that the issue is resolved.

Discussion0

Share your experience and ask questions. Comments without links appear after editorial review.

No comments yet. Start the discussion.