Run a Bash Script with Cron
To run a bash script from cron, give the absolute path to the script and make sure it is executable. Cron runs with a minimal environment, so hard-code paths and set the shell if your script relies on bash features.
The crontab line
Run crontab -e and add (this runs at the top of every hour):
0 * * * * /usr/bin/bash /home/user/scripts/job.sh >> /home/user/scripts/job.log 2>&1
Make the script executable
chmod +x /home/user/scripts/job.sh. Start the file with a shebang: #!/usr/bin/bash.
Why absolute paths matter
Cron's PATH is usually just /usr/bin:/bin. Commands your script calls (like docker, aws, node) may not resolve — use full paths inside the script or set PATH= at the top of the crontab.
Capture output
Append >> job.log 2>&1 so both stdout and errors land in a file. Without this, cron emails output (or silently drops it), making failures hard to debug.
FAQ
Why does my bash script work manually but not in cron?
Almost always the environment: cron has a minimal PATH and no shell profile. Use absolute paths to every command and the script itself, and set PATH at the top of the crontab if needed.
Do I need chmod +x for a cron script?
If you call it as /bin/bash script.sh, no. If you call it directly as /path/script.sh, yes — it must be executable and have a shebang line.
How do I see errors from a cron bash script?
Append >> /path/job.log 2>&1 to the cron line so stdout and stderr are written to a log you can inspect.