Automate tasks with Crontab on Ubuntu


Are you running Ubuntu and tired of handling some tasks on your own computer? With a little effort these manual tasks should not be a problem, as you can easily schedule them.

ubuntu, linux, crontab

Linux comes with a very useful feature, Crontab. This function is used for scheduling and automating tasks. Although in this article we use Ubuntu as an example, the following steps will work for any Linux distribution.

Use Crontab to schedule and automate tasks on Ubuntu
Cron performs the same function as the task scheduler in Windows. With this utility, you can choose a preferred time for any process you want to start, whether it is backup work or maintenance, and of course without any manual intervention.

However, before delving into the use of Crontab, it is important to understand the structure and layout for creating jobs in it.

Basic elements for the organization of the work Crontab

mhsunmondowusercommand OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO_
|||||
|||||
||||─────────day of the week (0-6) (0 is Sunday)
|||────────────month (1 to 12)
||───────────────day of the month (1-31)
|──────────────────time (0-23)
─────────────────────min (0 - 59)

m - represents the minute and can be any number from 0 to 59.
h - represents the hour (hour) and can be any number from 0 to 23.
sun - represents the day of the month and can be any number between 1 and 31.
mon - represents month. You can explicitly specify the month in which you want a task to be executed. The range is 1 to 12.
dow - do you want a task to be performed on a specific day of the week? You can select a number between 0 and 6.
user - if you have more than one user in Ubuntu, you can specify who is responsible for the task.
command - after selecting the time and user account, you must write a command for the task itself.

How to use Crontab to schedule a backup in Ubuntu
Having explained the tools you will use to automate tasks in Ubuntu, see how you can schedule a backup task:

1. Launch a terminal, either from the Applications menu or by pressing Ctrl + Alt + T.

2. Enter the command:
crontab -e

3. If you are running it for the first time, it will ask you to select the editor to open the file. Choose nano as the easiest.

ubuntu crontab

4. In the opened crontab file, scroll down to the end of the file with the down arrow key. To add a task to run at a specific time, add your task to the following format:
m h dom mon dow /file/path/to/command

For example, to run a backup script at 5 a.m. every Monday:

0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

ubuntu crontab 2

5. When done, press Ctrl + O at the same time to save the file to the nano processor. Then press Ctrl + X to exit the nano editor.

With these instructions it will be quite easy for you to schedule tasks in Ubuntu.


Read them Technology News from all over the world, with the validity of iGuRu.gr

Follow us on Google News iGuRu.gr at Google news