Ubuntu Cronjob: Explanation and Setup
Related Videos: How to schedule a Cron Job to run a script on Ubuntu 16.04 (May 2024).
A useful tool in Ubuntu are so-called cron jobs. We'll explain how to set it up and use it.
Ubuntu cronjob - what is it?
- A cron job - also called a crontab - is a command that executes scripts and programs at a specified time. It is therefore suitable, for example, for making backups or performing updates.
- Please note, however, that a cron job is only executed if your computer is really switched on. Missed cron jobs will not be made up for.
- A cronjob consists of 7 sections. The first stands for the minute and the second for the hour in which the task is completed. The third section contains the day of the month and the fourth the month itself. The fifth is the day of the week, with the numbers 0 and 7 each representing Sunday. The sixth section lists the user for whom the cronjob is being executed. Finally, the task itself is noted.
- Cron jobs are either stored system-wide in the directory "/ etc / crontab" or for individual users under "/ var / spool / cron / crontabs".
Create Ubuntu cronjob - that's how it's done
- The cronjob service for the terminal is already included in Ubuntu. Therefore no installation is necessary.
- To create or change a cron job, open the terminal and type "crontab -e". If you want to edit another user's cron jobs, enter "crontab -u user -e" and replace "user" with the desired user.
- Now you can choose which editor you want to use to edit your cron jobs. We recommend using nano as it is the easiest way.
- Use the arrow keys to navigate to the bottom of the document and enter your cronjob. If you do not need a parameter, simply fill it with "*". For example, if you want to do a cron job every day at 3:30 a.m., you only need to fill in the hours and minutes, instead of the rest of the values there is an "*".
- When you are finished, press [Ctrl] and [X] simultaneously and confirm with [J] and [Enter]. Your changes are saved and closed nano.
- To list all your cron jobs, type the command "crontab -l". To see another user's cron jobs, type "crontab -u user -l". Replace "user" with the name of the desired user.