A cron @reboot entry that never seems to run
@reboot entry in crontab -l but nothing happens after the restartShort answer
@reboot runs the command once after the machine reboots, in cron's small environment, not your login shell. The job often runs and fails silently. Redirect its output to a file to see the real error, then use absolute paths, set variables inside the crontab, and escape any % sign.
Fix it fast
1Find out which cause you have
Send the job's output to a file, so the failure is visible. Edit the entry, reboot once, and read the file.
crontab -e # change the line to: @reboot /home/deploy/start.sh >> /home/deploy/reboot.log 2>&12Match what you see, then jump to its fix
- 1
The log shows a missing program or file that exists when you run the same line in a terminalThe job runs in cron's small environmentFix - 2
The command is cut off after the first % and the rest arrives as inputA % sign in the command is turned into a newlineFix - 3
No error shown anywhere, because the output went to mail or was discardedThe job ran but its output was lostFix
- 1
What does the error look like?
@reboot entry in crontab -l but nothing happens after the restartthe script works in a terminal and fails from cronno output, no mail and no error from the job
Cause 1 of 3
The job runs in cron's small environment
1Check
cron starts the command with /bin/sh, not your login shell. Only SHELL, LOGNAME and HOME are set for you, so nothing from .bashrc or .profile is loaded: no PATH additions, no nvm, no virtualenv.
@reboot env > /home/deploy/cron-env.txt 2>&12Fix
Use absolute paths for the program and the script, and set what the job needs at the top of the crontab. Variables are written as NAME=value on their own line.
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
@reboot /usr/bin/node /srv/myapp/server.js >> /srv/myapp/reboot.log 2>&13Verify
Reboot and read the log file.
sudo reboot
# after login
tail -n 20 /srv/myapp/reboot.logConfirmed by manpages.ubuntu.com
Cause 2 of 3
A % sign in the command is turned into a newline
1Check
In a crontab, an unescaped % ends the command; everything after it is sent to the command as standard input. This hits date +%F and similar format strings.
crontab -l | grep '%'2Fix
Escape each % with a backslash, or move the command into a script file and call the script.
@reboot /usr/bin/touch /home/deploy/started-$(/bin/date +\%F).flag3Verify
Reboot and check that the file name contains the date.
ls /home/deploy/*.flagConfirmed by man7.org
Cause 3 of 3
The job ran but its output was lost
1Check
cron mails a job's output to the crontab owner, to the address in MAILTO if it is set. If MAILTO is set to an empty string, no mail is sent at all, so errors disappear.
crontab -l | grep -i mailto
mail2Fix
Redirect standard output and standard error in the entry itself, and keep the log file where the crontab's user can write it.
MAILTO=""
@reboot /home/deploy/start.sh >> /home/deploy/reboot.log 2>&13Verify
Reboot and read the file; it now holds the script's own messages.
cat /home/deploy/reboot.logConfirmed by man7.org
How do I stop it coming back?
- Redirect output to a log file in every cron entry, so a failure is never silent.
- Use absolute paths for every program and file in the entry.
- For a long-running service that must restart on failure, write a systemd unit instead of an @reboot line.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
A cron job on EC2 never runs, or runs and does nothing
A warning will be written to syslog.
Cron runs commands with a minimal environment through /bin/sh.
4 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix