crontab examples: schedule a script to run automatically
Run a script every minute, hour, day or week.
Cron runs commands on a schedule. Choose how often, enter the full path of your script, and copy the crontab line. Then add it with crontab -e.
Create your config file
Type your own values. The file below updates as you type, and nothing you type leaves your browser.
*/5 * * * * /home/me/backup.sh >> /home/me/cron.log 2>&1How this setup works
Step-by-step setup
- Make your script executable: chmod +x /home/me/backup.sh.
- Open the schedule: crontab -e.
- Paste the line above.
- Save and exit. Check with crontab -l.
What the important lines mean
- Your schedule */5 * * * * reads: minute, hour, day of month, month, day of week.
- */5 means every 5 units.
- >> file 2>&1 saves the output and errors to a log file.
Common errors and how to fix them
- Job does not run
- Use full paths. Cron has a small PATH, so python may not be found; write /usr/bin/python3.
- Script works by hand, not in cron
- Check the log file /home/me/cron.log and that the script is executable.
Frequently asked questions
- How do I run a cron job every 5 minutes?
- Use */5 * * * * followed by the command. Pick "Every 5 minutes" above to get the line.
- Why is my cron job not running?
- Most often the command needs a full path, the script is not executable, or it depends on environment variables cron does not have. Send the output to a log file and read it.
- What do the five cron fields mean?
- In order: minute, hour, day of the month, month, and day of the week. A star means every value.
Free tools that help
- Cron expression explainerPaste a cron expression to see what it means in plain English and when it will run next. Checks ranges, steps, names and @daily-style shortcuts.
- chmod calculatorTick read, write and execute for owner, group and others to get the chmod number, symbolic form and command. Or type 755 and see what it means.
More server configs
- systemd service fileRun your app in the background and start it automatically at boot.
- Apache virtual hostHost a website from a folder with Apache, with or without .htaccess.
- logrotate configKeep log files from filling your disk: rotate, compress and delete old logs on a schedule.
- fail2ban jail.localBan addresses that keep failing to log in. Choose ban time, retries and which services to protect.
- PM2 ecosystem.config.jsRun a Node.js app with PM2: restarts on crash, memory limit, cluster mode and start at boot.
- WireGuard server config (wg0.conf)Set up a WireGuard VPN server on Linux with one peer, NAT and the right commands.