# Cron job

> A command a computer runs on its own on a schedule, like every night at 3 a.m.

- Level: Intermediate
- Topics: Software
- URL: https://tidbit.legios.com.ar/cron-job/
- In Spanish: [Cron job](https://tidbit.legios.com.ar/es/cron-job/)

**Cron** is a scheduler that has come with Unix-like systems since the 1970s. Its job is to run commands at set times. Each scheduled task is a **cron job**: back up the database every night, send a report every Monday, clean out old files every hour. The list of jobs lives in a file called the **crontab**.

Every job has a schedule written as five fields: minute, hour, day of the month, month and day of the week. An asterisk means "any". So `0 3 * * *` means "at minute 0 of hour 3, every day", and `*/15 * * * *` means every fifteen minutes. The notation is compact and famously easy to get wrong, so people often check it with an online tool before saving.

The idea outlived the tool. Cloud schedulers, Kubernetes, GitHub Actions and many hosting platforms let you schedule tasks with the same cron syntax. Two classic traps: the schedule runs in the server's time zone, which may not be yours, and a failed cron job makes no noise unless someone set up logs or alerts to notice.

## An analogy

An alarm clock with a to-do list taped to it. When it rings, the task gets done on its own, whether anyone is awake or not.

## Keep in mind

- A cron job is a command scheduled to run automatically.
- Schedules use five fields: minute, hour, day of month, month, day of week.
- `0 3 * * *` means every day at 3:00.
- Check the time zone and add alerts: failures are silent by default.

## Go deeper

- [Cron on Wikipedia](https://en.wikipedia.org/wiki/Cron)
- [crontab(5) manual page](https://man7.org/linux/man-pages/man5/crontab.5.html)

## Related terms

- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Kubernetes](https://tidbit.legios.com.ar/kubernetes/): The system that runs and babysits containers across many machines.
- [GitHub](https://tidbit.legios.com.ar/github/): A website where teams store their code with Git and work on it together.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
