
When a cron job does not run on a VPS, the cause is almost never cron itself: it is the environment it runs in. cron starts with a minimal environment, without your PATH, without your terminal and without your working directory. The command that works at the prompt fails there. The cure is to use full paths, redirect the output to a file, and read that file.
Step by step
|
|
|
|
|
|
The causes, in order of frequency
| Symptom | Cause and remedy |
| Works in the terminal, fails in cron | Minimal PATH and environment. Full paths for the program and the files; variables defined in the crontab itself or in the script. |
| Nothing in cron’s log | The service is stopped, or the crontab has a syntax error. The five time fields are: minute, hour, day of month, month, day of week. |
| The script “has no permission” | The execute bit is missing (chmod +x script.sh), or the cron user cannot read the folder: file permissions. |
| A line with % breaks | In a crontab, % means newline. Escape it with \%, for example in date +\%F. |
| Runs at the wrong hour | cron uses the server’s time zone. See it with timedatectl. A job “at 2” is at 2 in that zone, not yours. To set it: the VPS time zone and clock. |
| Runs, but does nothing | The command ends with an error nobody sees. Without output redirection, cron tries to mail it to a local mailbox nobody reads. |
| Runs twice at the same time | The previous run has not finished. Use flock to prevent overlaps. |
| Do not edit another user’s crontab by mistake. A job that writes files as root into a site folder leaves them owned by root, and the site can no longer change them. Put the job in the crontab of the user who owns the files (sudo crontab -e -u username). |
| Be careful with jobs that delete. Rehearse by hand first, with a test folder. A line with a mistyped path and an rm is hard to undo, and on a VPS the backups are yours: backing up a VPS. |
| For PHP jobs and automatic backups we have ready-made articles: running a PHP script from a cron job and automatic backups of your own application. On cron in general and in the hosting panel: cron jobs. |
|
Questions about what is on our side, such as the machine being up or the network? Open a ticket and we will check. Open a support ticket |
|
SEE ALSO Where the logs are on a Linux VPS |
RECOMMENDED PRODUCT VPS server with root access Resources of your own, the OS you choose, reinstall whenever you like. from $8.39/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











