Scheduling a Bash script with cron turns a command that already works in the terminal into a recurring background job. The important handoff is not only the time expression; cron also needs an executable script path, a shell, and enough environment to run without your interactive profile.

A per-user crontab is the safest starting point when the job should run as your own account. Each job line has five time fields followed by the command, and separate environment lines such as SHELL, PATH, and MAILTO can be placed above the schedule.

Cron starts jobs with a smaller environment than an interactive Bash session. Use absolute paths, put reusable logic in a script with a #!/bin/bash shebang, redirect output to a log you can inspect, treat schedule times as the host cron daemon's local time, and list the crontab after saving so the installed schedule is visible before the next run time arrives.

Steps to schedule Bash scripts with crontab:

  1. Create or choose the Bash script that cron should run.
    $ mkdir -p "$HOME/bin"
    $ vi "$HOME/bin/report.sh"
    #!/bin/bash
    set -euo pipefail
     
    printf 'report completed: %s\n' "$(/usr/bin/date -Is)"

    The script path can be different, but the crontab entry should use the full path instead of relying on the current working directory.

  2. Make the script executable for the file owner and run it once from the shell.
    $ chmod u+x "$HOME/bin/report.sh"
    $ "$HOME/bin/report.sh"
    report completed: 2026-06-04T03:00:01+00:00

    Fix script errors before adding the cron entry. Cron will not provide your interactive prompt, aliases, shell functions, or unsaved terminal variables.

  3. Decide on the schedule and command line.
    # m h dom mon dow command
    0 3 * * * /home/alice/bin/report.sh >> /home/alice/report.log 2>&1

    The five fields are minute, hour, day of month, month, and day of week. This example runs the Bash script every day at 03:00 and appends standard output and errors to a log file.

  4. Open the current user's crontab in the editor selected by $VISUAL or $EDITOR.
    $ crontab -e

    Use sudo crontab -u username -e only when the scheduled script must run as a different account. The file edited with crontab -e is a user crontab, not /etc/crontab, so it does not include a username column.

  5. Add the Bash environment lines and the scheduled script entry, replacing alice with the account that owns the script.
    SHELL=/bin/bash
    PATH=/usr/local/bin:/usr/bin:/bin
    MAILTO=""
    0 3 * * * /home/alice/bin/report.sh >> /home/alice/report.log 2>&1

    SHELL=/bin/bash makes cron run the command with Bash. Keep PATH explicit, and add any additional command directories your script needs.

    If the cron command itself contains a % character, escape it as \%. Cron treats unescaped percent signs in the command field as line breaks passed to the command.

  6. Save the file and exit the editor so crontab installs the updated schedule.

    A normal Linux cron daemon reloads the saved user crontab automatically. A service restart is not usually required after crontab -e saves successfully.

  7. List the installed crontab and confirm the Bash script entry appears exactly as intended.
    $ crontab -l
    SHELL=/bin/bash
    PATH=/usr/local/bin:/usr/bin:/bin
    MAILTO=""
    0 3 * * * /home/alice/bin/report.sh >> /home/alice/report.log 2>&1

    This is the immediate success check for the scheduling change. If the job belongs to another account, list that account's crontab with sudo crontab -u username -l.

  8. After the next scheduled run time passes, inspect the redirected log from the Bash script.
    $ cat /home/alice/report.log
    report completed: 2026-06-04T03:00:01+00:00

    A new line in the log confirms that cron matched the schedule, launched Bash, and ran the script under the account that owns the crontab.