How to Set Up Daily Cron Jobs on Ubuntu

If you’re running Ubuntu, you might want to make your system do something every day without having to remember it yourself.

This is where cron jobs help.

In this post, I’ll show you how to set up a daily cron job on Ubuntu. It’s something I use often on my servers to automate tasks like backups, updates, and log cleanups.

We’ll keep everything simple. You won’t need any advanced skills. Just a little time and a working Ubuntu system.


What is a Cron Job?

Let’s define the basics first.

A cron job is a command or script that runs automatically at scheduled times.

Cron is the tool that checks the schedule and runs the job.

Job is what you want to run. That could be a script, a command, or anything else the system understands.

Think of it like setting an alarm clock — but instead of waking you up, it runs your task.

You can run a job every minute, hour, day, week, or even once a month. But here, we’ll focus on daily jobs.


Why Use Daily Cron Jobs?

Daily jobs are useful when you want something to happen once every day — like at 1 AM or 10 PM.

I use daily cron jobs to:

  • Back up important folders to another server
  • Update software packages
  • Clear old logs
  • Send email reports

You probably have things you want to automate, too.

Have you ever forgotten to back something up? Or missed cleaning up temporary files? A cron job can take care of it.


How Cron Works on Ubuntu

Ubuntu uses something called crontab.

Each user on the system can have their own crontab file, which holds the list of scheduled jobs.

There are also system-wide cron directories like /etc/cron.daily and /etc/crontab. These are for global tasks.

So, there are two main ways to run a daily cron job:

  • Use your personal crontab with a specific schedule
  • Place your script in Ubuntu’s /etc/cron.daily folder

We’ll look at both.


Method 1: Using Your Personal Crontab

This is my preferred method because it gives you control.

Step 1: Open the Crontab File

Type this in your terminal:

crontab -e

The first time, it might ask which editor you want to use. Choose nano if you’re not sure.

Step 2: Add a Line for Your Job

To run a job every day at 2:00 AM, write:

0 2 * * * /home/youruser/myscript.sh

Let’s break that down:

  • 0 – minute (0 means on the hour)
  • 2 – hour (2 means 2 AM)
  • * * * – every day, every month, every weekday
  • /home/youruser/myscript.sh – this is your script or command

Save the file and exit (Ctrl + X, then Y, then Enter).

That’s it. Cron will now run your script daily at 2 AM.

Make sure your script is executable:

chmod +x /home/youruser/myscript.sh

Method 2: Use /etc/cron.daily

Ubuntu also runs everything inside /etc/cron.daily once a day.

This is great for system-wide scripts.

Step 1: Create Your Script

Create a new script file:

sudo nano /etc/cron.daily/my-daily-task

Paste your script or command inside.

Example:

#!/bin/bash
rsync -av /home/youruser/docs /mnt/backup/docs

Step 2: Make It Executable

sudo chmod +x /etc/cron.daily/my-daily-task

That’s it. Ubuntu will run this script once a day, usually around 6:25 AM.


Two Helpful Lists

Tasks You Can Automate with Cron

  • Download website backups
  • Run system updates
  • Monitor disk space
  • Rotate logs
  • Sync files between servers

Benefits of Using Cron

  • Saves time
  • Reduces mistakes
  • Keeps your system clean
  • Works quietly in the background
  • Runs even when you’re not around

How to Check If It’s Working

After setting up your job, you’ll want to make sure it runs.

You can:

  1. Add logs to your script. For example:
echo "Backup started at $(date)" >> /home/youruser/backup.log
  1. Check cron logs:

On Ubuntu, cron logs are stored in the system log.

Run:

grep CRON /var/log/syslog

It will show you when jobs were started and finished.


Comparing the Two Methods

Both ways work well, but they have some differences:

Feature crontab -e /etc/cron.daily
Who can use it? Any user Only root or admin
Schedule control Exact time (you pick) Fixed time (default ~6:25 AM)
Good for Custom tasks System-level scripts
Needs sudo? No Yes

Personally, I use crontab -e for most of my personal automation tasks.


Common Problems

1. Cron job doesn’t run

Check:

  • Is the script path correct?
  • Is the script executable?
  • Does the script work when run manually?

2. No output from the script

By default, cron doesn’t show anything unless there’s an error.

You can send output to a file:

0 2 * * * /home/youruser/myscript.sh >> /home/youruser/output.log 2>&1

3. Wrong environment

Cron uses a very limited environment. It may not know your PATH or other settings.

Fix it by using full paths to commands. Instead of python, use /usr/bin/python.


Tips From My Own Use

When I first started using cron, I made a simple mistake — I forgot to make the script executable. It didn’t run, and I thought cron was broken.

I also used relative paths in scripts, which sometimes failed. Now I always use full paths.

Over time, I’ve come to rely on cron. It does small jobs every day that would be annoying to do by hand.

And when something doesn’t run, checking the logs always helps.


Final Thoughts

If you want your Ubuntu system to take care of things automatically each day, cron jobs are the way to go.

They’re quiet, dependable, and not too hard to set up.

Do you already use cron? What kind of daily tasks would you like to automate?

Feel free to try both methods — your crontab and the /etc/cron.daily folder. Both are useful, and each has its place.

Let me know if you need help writing a script or picking a schedule.

Once you get the hang of it, cron becomes one of the most useful tools on your Linux machine.

Leave a Reply