In almost every case, a cron job that "isn't running" your shell script is actually running it — it just fails silently because cron uses a minimal environment, no shell profile, and often the wrong paths or permissions. The fix is usually one of five things: use absolute paths, point cron at the right interpreter, set the executable bit, check for Windows line endings, and capture output so you can see the real error. This guide walks through diagnosing and fixing the problem on Linux and macOS.

What You'll Need

  • Access to a terminal on the machine running cron (local or via SSH)
  • Permission to edit your crontab (your own user's crontab needs no special rights; the system crontab or root's crontab needs sudo)
  • The path to your script, e.g. /home/you/scripts/backup.sh

Step-by-Step

  1. Confirm cron itself is running. Run ps aux | grep cron (on some systems the daemon is called crond). If nothing shows up, start the service with sudo systemctl status cron (Debian/Ubuntu) or sudo systemctl status crond (RHEL/Fedora/CentOS), and start it if it is stopped. On macOS, cron runs via launchd and is normally active once you create a crontab.
  2. Check the crontab actually contains your entry. Run crontab -l for your user. If you edited a file like /etc/crontab or a file in /etc/cron.d, remember those require a username field between the schedule and the command; a user crontab does not. A mismatch here is a common cause of "nothing happens."
  3. Verify the schedule syntax. A crontab line is five fields: minute, hour, day of month, month, day of week, then the command. For example, 0 3 * * * /home/you/scripts/backup.sh runs daily at 03:00. A quick sanity test is * * * * * (every minute) while debugging — just remember to change it back.
  4. Use absolute paths everywhere. Cron runs with a minimal PATH (often just /usr/bin:/bin). Replace bare commands like python3 or tar with full paths such as /usr/bin/python3 — find them with which python3. Likewise, call your script by its full path, and inside the script, avoid relying on the current directory: cron runs jobs from your home directory, not from where the script lives. Add cd /path/to/project || exit 1 at the top of the script if it depends on relative paths.
  5. Make the script executable and readable. Run chmod +x /home/you/scripts/backup.sh and confirm with ls -l. Also make sure every directory in the path is accessible to the user cron runs the job as.
  6. Point cron at the interpreter if needed. If your script lacks a shebang line (#!/bin/bash as the very first line), either add one or invoke the shell explicitly: 0 3 * * * /bin/bash /home/you/scripts/backup.sh. If you edited the script on Windows, check for CRLF line endings — run sed -i 's/\r$//' script.sh or convert with dos2unix. A \r after the shebang makes the kernel fail with a confusing "bad interpreter" error.
  7. Capture the output so failures are visible. Cron mails output to the local user mailbox, which most people never read. Change your entry to log to a file: 0 3 * * * /home/you/scripts/backup.sh >> /home/you/cron.log 2>&1. The 2>&1 captures stderr as well as stdout — most errors go to stderr.
  8. Replicate the cron environment to test. Run env -i /bin/bash -c '/home/you/scripts/backup.sh' to execute the script with an empty environment, close to how cron runs it. If it works in your normal shell but fails here, the difference is almost certainly environment variables (PATH, JAVA_HOME, etc.). Either export them at the top of the script, add SHELL=/bin/bash and PATH=/usr/local/bin:/usr/bin:/bin lines at the top of the crontab, or source the profile you need inside the script: source /home/you/.profile.
  9. Check permissions and ownership of cron files. If you placed a script in /etc/cron.daily or similar and it is not running, ensure it is owned by root and not writable by others — some cron implementations silently skip scripts with loose permissions. A file named with a dot extension (e.g. script.sh) may be ignored by run-parts; remove the extension.
  10. Watch syslog for evidence. Check grep CRON /var/log/syslog (Debian/Ubuntu) or journalctl -u cron (or crond) to confirm cron attempted the job. On macOS, look in Console or log show --predicate 'process == "cron"'. If cron shows the job firing but nothing happens, the problem is inside the command, not the schedule.

Common Mistakes

  • Assuming cron inherits your interactive shell's environment — it does not load .bashrc, .bash_profile, or aliases.
  • Editing the crontab with crontab -e but forgetting to save, or editing a crontab file directly without reloading; user crontabs must be edited via the crontab command.
  • Using % in a cron command without escaping it — in a crontab, % is treated as a newline. Escape it as \%, or move the command into the script.
  • Forgetting the extra username field required in /etc/crontab and /etc/cron.d files.
  • Writing relative paths like ./backup.sh or ~/scripts/backup.sh — the tilde works in cron but relative paths usually do not.
  • Overlapping runs: a long job launched every minute can pile up. Use a lock (for example flock /tmp/myjob.lock /path/script.sh) to prevent concurrent runs.

Tips

  • Put environment setup inside the script rather than the crontab — it keeps the script working when run manually too.
  • For a quick visual check of a schedule, several online cron expression analyzers will show you the next few run times.
  • Log a timestamp at the start of the script (date >> /home/you/cron.log) so you can tell whether it ran at all versus ran and failed early.
  • If your machine is off or asleep at the scheduled time, cron simply skips the job. Consider anacron for daily jobs on laptops, or schedule around uptime.
  • End your script with exit 0 on success and non-zero on failure, so failures are distinguishable in logs and monitoring.

Troubleshooting

No log file is created at all: cron never executed the line. Recheck the crontab entry, the schedule fields, and that the cron daemon is running. Try a minimal test entry: * * * * * /bin/echo test >> /tmp/crontest.txt and wait two minutes.

Log exists but shows "command not found" or "No such file or directory": it is a path problem. Use absolute paths for the interpreter, the script, and every command the script calls.

"Permission denied": run chmod +x on the script and check the user the job runs as — root's crontab and your user's crontab are different files.

"bad interpreter" error: usually CRLF line endings from a Windows editor. Convert the file to Unix line endings.

Works manually, fails in cron: environment differences. Test with env -i, then export the missing variables inside the script.

Job runs but behaves differently: cron changes the working directory to the user's home. Add an explicit cd to the script.

If none of that resolves it, read the raw cron logs for your system (syslog, journalctl, or Console on macOS) — cron records every job it launches, which narrows the problem to scheduling versus execution.

Frequently Asked Questions

How do I see errors from my cron job?

Redirect output in the crontab line: append >> /path/log 2>&1 to the command. Without this, output goes to local mail that is rarely read.

Does cron load my .bashrc or .profile?

No. Cron runs commands with a minimal environment. Either set variables at the top of the script or source the profile explicitly from within the script.

Why does my script work manually but not from cron?

Almost always PATH or working directory. Cron's PATH is minimal and its working directory is your home. Use absolute paths and cd inside the script.

Does cron run jobs if the computer was off at the scheduled time?

No, standard cron skips them entirely. Use anacron (for periodic daily/weekly jobs) or schedule the job for times the machine is on.

Can I run a cron job every 30 seconds?

Not directly — cron's smallest unit is one minute. The common workaround is a script with a loop that sleeps 30 seconds and runs the task twice, launched once per minute.

What user does my cron job run as?

Whatever user's crontab it lives in. crontab -e edits your user's crontab; sudo crontab -e edits root's. System files in /etc/cron.d specify the user in each line.