crontab of linux command

Definition:
There are some commands or scripts that can be executed manually when people are there, but some need to be executed every hour or at a certain time in the morning. At this time, a program similar to an alarm clock is needed to follow the time we set Let's run my own task-crontab

Main parameters:
-e edit crontab tasks
-l view the crontab tasks of this user
-r delete crontab tasks, but I generally don't use them, just delete or comment -e

Let's talk about how to add a crontab task to
execute crontab -e to add a new crontab task, just like a file in vi, you can edit it after pressing i.
crontab of linux command
At the beginning, there are five *, which represent the time, hour, minute, month, and week. Then I like to execute the environment variable first, because I have encountered the problem of failing if the environment variable is not executed before, and finally keep up with the command or script you want to execute.

* Here are some examples to better understand the meaning of: *
(1) 4:00 daily execution of the script
0 4
/ Profile; SH /home/zhou/test.sh.

(2.) Execute script
25 6,10,22 *. /Profile; sh /home/zhou/test.sh at 6:00, 10:00, and 22:00 every day

(3.) In July of each year, execute the script at 7 o'clock from 3rd to 5th every week
0 7 * 7 3-5. /Profile; sh /home/zhou/test.sh

(4.) Execute the script every 5 minutes
/5 *. /Profile; sh /home/zhou/test.sh

Note the problem:
Task scheduling under Linux is divided into two categories, system task scheduling and user task scheduling.
User scheduling: crontab is divided into users. Everyone has the habit of setting the alarm clock. When we execute crontab -e, we are actually writing the files under the /var/spool/cron/ directory. Just enter this directory You will find that he is divided into users, each user has a separate file, which stores his own crontab tasks.
System task scheduling: The tasks that the system needs to perform periodically, such as writing cache data to hard disk, log cleaning, etc. The /etc/crontab file is the configuration file for system task scheduling.

The most frequently encountered problem is that crontab does not execute. You can check it as follows:

First, look at the status of the cron service first.
crontab of linux command
Second, see if the script permissions to be executed can be executed.
Third, see if the script path is correct.
Fourth, there is a time difference between the server and the client. The crontab must be executed according to the server time.
Fifth, if none of the above is true, you need to check whether the variables in the script can be referenced.

Guess you like

Origin blog.51cto.com/15013163/2555140