Automate tasks with Crontab on Ubuntu

You're running Ubuntu and you're tired of handling some tasks on your own your; With a little effort these manual tasks should not be a problem as you can easily schedule them.

ubuntu, linux, crontab

The 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

m h sun mon dow user command  OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO_
| | | | |
| | | | |
| | | | ────────── day of the weeks (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. To add a task for at a certain time, add your work in 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.

iGuRu.gr The Best Technology Site in Greecefgns

every publication, directly to your inbox

Join the 2.082 registrants.
ubuntu, linux, crontab

Written by Dimitris

Dimitris hates on Mondays .....

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).