Scheduling Tasks in Linux using Crontab

shape
shape
shape
shape
shape
shape
shape
shape

Scheduling tasks is a very useful feature, for example in server maintenance and backup, etc. In Linux, this can be done using“crontab“.

Using the crontab -operation command will allow you to add, list or remove your scheduled tasks.

Example:

crontab -e (edits scheduled tasks of the masterdaweb user)
crontab -l (displays the scheduled tasks of the masterdaweb user)
crontab -r (removes scheduled tasks from the masterdaweb user)

When editing a crontab, you should enter how often or for what period a certain action will be performed, for example:

10 02 * * * /home/masterdaweb/backup.sh

In our example above, this means that the“backup.sh” script will run every day at 02:10. The writing is backwards, the first field is the minutes and the second is the hours. The remaining three fields mean, in order, day, month and day of the week. The day of the week is specified from 0-6, each number representing a day of the week:

0 – Sunday
1 – Monday
2 – Tuesday

6 – Saturday

The asterisk used in the day, month and day of the week fields means that the above schedule applies to all days, months and days of the week. If we wanted, for example, to make the backup script run every minute, we would have to use an asterisk in all the fields:

* * * * * /home/masterdaweb/backup.sh

In “crontab language” the backup script would run every minute, every hour, every day, every month, every day of the week.

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.