cron
What is cron?
cron is the old time setup on Unix systems. The list is called crontab. Each line is five time fields and one command: minute, hour, day of the month, month, and day of the week. A star means every value of that field. The job opens under your user's name. It does not open a window. The result can go to mail or to a file. A systemd timer can do a similar job, but it is not cron itself.
What is cron used for?
cron is for a backup, a cleanup, and a night report. It is so you do not type the same command by hand every day.
- Taking a copy of the database every night
- Deleting an old temporary file
- Sending a morning report
- Running a check once an hour
What can you do with cron?
With cron you tie a command to a calendar. It does not check whether the command is right. When the path or the permission is wrong, the job can fall quietly. Because there is no screen, the result needs to be written to a file. The same job can start again before the last one has finished.
Is cron hard to learn?
Writing one line is easy. The difficulty is the time zone and the path. The server's clock may not be your clock. A short name inside the command may not be found in cron's environment. The full path is written. Putting the star wrong can run the command every minute.
Advantages and limits
Advantage: the job opens without you, the line is short, and it is ready on a Linux server. Limit: a mistake stays quiet and jobs can pile up. cron is not the program itself. It only calls the command when the time comes.
Basic ideas
Five fields say the time. The sixth part is the command. The user says under whose name the job opens.
- A star means every value
- 0 3 * * * is every night at 03:00
- crontab -l shows the list
- The result does not come to the screen by itself
A short example
This line calls a copy command every night at 03:00. The command itself is not written here, only its path.
0 3 * * * /usr/local/bin/backup
Common questions
- Is cron a programming language? No. It calls a ready command when the time comes.
- When the job falls, does it show on the screen? No. There is no window. The result has to be written to a file or a log.
- Does a star mean only Monday? No. A star means every value of that field.