crontab -e and add the line */5 * * * * /home/alex/backup.sh >> /home/alex/backup.log 2>&1. The five fields are minute, hour, day of month, month and day of week; */5 in the minute field means “every 5 minutes”. Save and exit; cron picks up the change automatically. Check it with crontab -l.
Before you start
- Connect with SSH.
- cron is a background service that runs commands on a schedule. Each user has their own list of jobs, called a crontab.
- Make sure cron is installed and running. Ubuntu and Debian call the service
cron, AlmaLinux and Rocky call itcrond(packagecronie):
- Ubuntu / Debian
- AlmaLinux / Rocky
How to add a cron job
1
Open your crontab
nano if unsure.2
Add a line at the bottom
>> file 2>&1 saves the output and errors to a log so you can see what happened.3
Save and exit
In nano press
Ctrl+O, Enter, Ctrl+X. You see crontab: installing new crontab.4
List your jobs
chmod +x /home/alex/backup.sh) and give it a first line such as #!/bin/bash.
How to read the crontab syntax
Crontab examples
Shortcuts also exist:
@hourly, @daily, @weekly, @monthly and @yearly.
Times use the server’s time zone, which is often UTC on a new server. Check it with
timedatectl and change it with set the time zone.How to run a job as root (system cron)
Use root’s crontab withsudo crontab -e, or create a file in /etc/cron.d/. Files there have an extra user field before the command:
/etc/cron.d/ may only contain letters, digits, - and _. A name with a dot, such as backup.cron, is skipped. For scripts that only need “roughly daily”, drop an executable script into /etc/cron.daily/.
How to check it worked
1
Wait for the next run
For a 5-minute job, wait up to 5 minutes.
2
Look at your log file
3
Check cron's own log
- Ubuntu / Debian
- AlmaLinux / Rocky
CMD (...) line.Why is my cron job not running?
Frequently asked questions
How do I run a cron job every 30 seconds?
cron’s smallest step is one minute. Use two lines, the second starting withsleep 30;, or use a systemd timer with OnUnitActiveSec=30s.
How do I delete a cron job?
Runcrontab -e and delete the line. crontab -r removes your whole crontab without asking, so avoid it unless you mean it.
How do I stop cron emailing me?
AddMAILTO="" at the top of the crontab, or redirect output with >> /path/to/log 2>&1.
How do I stop a job from running twice at once?
Wrap it inflock: */5 * * * * flock -n /tmp/backup.lock /home/alex/backup.sh. If the previous run is still going, the new one exits.
Related guides
VPS and dedicated server guides
Every server guide in one place.
Create a systemd service
For programs that run all the time.
Back up a Linux server
A job worth scheduling.
Set the time zone
Make cron run at the right hour.
Read logs with journalctl
Check that jobs ran.
Checked against the official Debian crontab(5) and cron(8) manuals and the Red Hat Enterprise Linux 9 documentation on 4 November 2026; crontab commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.
Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026