【 Cron in Linux 】What is it? + Characteristics and Uses ▷ 2022

If you’re linux user surely you have heard about what cron isthis is a tool very similar to , so its function is to allow the configuration of a program, process or file that is running on the system. In the case of the system linux operating this is not executed from a graphical environment, but from the terminal.

These types of functions are intended to help users to improve your productivity when working on said system, for this it is also important avoid starting repetitive tasks. By having a tool like cron users have the possibility of executing tasks according to the task schedule that has been previously established, offering them greater convenience of use.

Therefore, it can be said that cron is a linux task manager that allows to carry outon a certain momentthese can be scheduled to run every hour, every day, once a week, among others. To work with cron will need to be done through crontab command. This is how here we are going to teach you a little more about what this tool is about and how you can get the most out of it.

What is Cron and what is this Linux operating system service for?

cron is a Linux tool that allows you to perform background processes being This is a very important and common procedure in the system. The execution of the same occurs as soon as start computer boot and its main function is to be able to take care of all scheduled tasks with a specific date and automatically and repetitively. Each of the processes to be executed must be specified in the crontab file.

The operation of all this is very simple, there you must check if there are pending tasks for execution according to the system schedule. Please note that it is very important to have set the device time correctlysince depending on it, each of the pending activities will be carried out, this means that if the system time is not configured correctly, the results of the activities scheduled with cron will not be as expected.

Finally, it should be mentioned that depending on the distribution being used on Linux, It can be started using the directories /etc/init.do etc/rc,d/ and every minute it performs a check of the /etc/crontab or /var/spool/cron, locating there the possible pending tasks to be executed.

What kind of tasks can be performed from Cron? main applications

It is important to keep in mind that cron jobs is a linux command whose main function is to periodically execute a script or command indicated by the user. This is how this type of function is used to carry out the periodic or repetitive execution of related scripts with email notifications, routine data checks, database, starting programsamong other types of activities available there.

Therefore, in cron you will have the opportunity to execute any action that is repetitive, an example of this so that you can understand it better would be the following: Create a cron task to periodically execute a script that checks the temperature of any weather station, this will let you know the temperature of the area and frequently display it on your website.

See also  【+10 US VPN Providers】List ▷ 2022

When you are creating this task you will have the opportunity to indicate with what how often the script should be executedeither every minute, every hour, 10 times a day, or just a few days a year. The programming of this activity will depend mainly on the needs of each of the users and the objectives they want to achieve with it.

Learn step by step how to use Cron in Linux like an expert

if you are a new linux user and you still don’t know very well how to use the cron tool on your computer, So here we are going to show you step by step how you can use it as quite an expert.

To do this, follow each of the steps that we are going to teach you below:

Start Cron

It must be borne in mind that cron is a service that only needs to be started once, mostly starts with the same system boot automatically. East cron service is known as crond and is available in all Linux distributions. Also keep in mind that in most Linux distributions this service is installed automatically and is always started at boot time.

This can be purchased in the following ways:

  • #> /etc/rc.d/init.d/crond status
  • #> /etc/init.d/crond status

Here you can use either one depending on the distro you use.

Now if you have the service command installed on the computer then use the following:

  • #> service crond status. Crond (pid 507) is running.

Another way to check all this is by checking it through the ps command:

If for some reason you have noticed that the cron command is not working or is working in the wrong way then you can check it as follows:

  • #> /etc/rc.d/init.d/crond start

If for some reason the cron service is not configured to run at boot from scratch you can fix it via the >chkconfig command:

  • #> chkconfig –level 35 crond on

In this way you will add it to the runlevel 3 and 5 so that it starts at the moment of system boot.

Use Cron from etc directory

Another way to use cron is through the etc directory from two ways, with the first one you will find the following directories:

  • Cron daily.
  • Cron weekly.
  • Cron hourly.
  • Cron monthly.

By placing a script file in any of these directories, then the script file It will be configured so that it can be executed every hour, every day, every week, every month, depending on the directory that has been selected.

See also  【 TALK on WHATSAPP Without Being Online 】 Step-by-step guide ▷ 2022

However, for the file to be executed it must look something like the following:

#!/bin/sh #script that generates a backup cd /usr/documents tar czf * backup cp backup /other_directory/.

As you can see the first line starts with the symbols #!, This indicates that it is a bash shell scriptwhile the other lines are about commands that we want run the script.

It can be called as a backup and change the corresponding permissions so that it can be executed, for example:

#> chmod 700 backup.sh #> ls -l backup.sh -rwx—— 1 root root 0 Jul 20 09:30 backup.sh

As you can see in the owner permissions group there is a x(rwx) this indicates that it can be executed. If said script file is left with cron hourly, it will be running every hour with one minute of every day.

The other way to be able to use cron is by directly manipulating the /etc/crontab file, during its installation by default in some of the Linux distributions it will look like this:

#> cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 01 * * * * root run-parts / etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly #> cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 01 * * * * root run-parts / etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly

The first four lines are variables that indicate the following:

  • Shell: Its about low shell which one is running cron, in the event that this is not specified, then the one indicated in the /etc/passwd line corresponding to the user who is executing the cron at that moment will be taken by default.
  • Path: It is the one that is in charge of indicating the path of the directories in which cron will look for the command to execute. It should be mentioned that this path is different from the system or user global path.
  • Email to: This is where the output of the command is sent if it has an output. Then cron will send a mail to whoever is specified in this variable, so it must be a valid user on the system or some other system. Now if this is not specified, then cron will send mail to the owner of the command being executed.
  • Home: It is the root or main directory of the cron command, if this is not indicated, then the root will be the one indicated in the /etc/passwd file corresponding to the user running cron.

The commands will always be indicated with the symbol of # at the beginning of the line, this will allow you to tell them apart. After all the above you will find the lines that execute the scheduled tasks themselves.

Keep in mind that here there are no limits to how many tasks there can be, the fields are usually seven and all these lines are formed as follows:

  • Minute: is in charge of controlling the minute of the hour in which the command will be executed, this is a value that must be between the range of 0 and 59.
  • Hour: here the time in which the command will be executed will be controlled, for this a specified 24 hour format and these values ​​must be within a range of 0 and 23 or in such a case 0 which would be midnight.
  • Day of the month: you must indicate the day of the month on which the command is to be executed, if you want to execute it the command on the 15th of the monththen you must place 15.
  • Month: In the event that you want the command to be executed in a specific month, then here you must select it, for this it can be indicated by a number that must go between 1 and 12 or by the name of the month in English or only the first three letters of the month.
  • Weekday: if it is going to be executed one day a week, then you can indicate it with a numeric value between 0 and 7 or by the name of the day in English or just put the first three letters of the day.
  • User: The user who is running the command.
  • Command: command, program or script that you want to execute, this is a field that can contain multiple spaces or words.
See also  【 The 'Snyder Cut' Fandom Was Always a Fraud 】 ▷ 2022

In this way you can start to specify when you want execute a specific task.

Using Cron with Crontab

In the case that you want run cron on multiple users, then it will be necessary to do it with crontab, for this we must bear in mind that linux it’s a multi-user operating system and cron is a service that has been created for it, so it will be able to develop very well. In this case, each of the users can count on their own crontab filein fact the etc/crontab file is assumed to be the root user’s file, but nothing happens if other users are included.

In this way, it will also indicate who is the user that is executing the task and it is mandatory in /etc/crontab. But in the case that users have to generate their own crontab file, then it will be necessary to use the crontab command. In the /var/spool/cron directory it may vary depending on the…

Loading Facebook Comments ...
Loading Disqus Comments ...